JAVASCRIPT Flashcards

1
Q
  • How do youdeclarea variable?
A

var nameOfVariable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • How do you initialize (assign a value to) a variable?
A

nameOfVariable = sting, number, or boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  • What characters are allowed in variable names?
A

letter, underscore, or dollar sign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • What does it mean to say that variable names are “case sensitive”?
A

superMan will be different than superman

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • What is the purpose of a string?
A

for letters and other characters not considered code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • What is the purpose of a number?
A

to display numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  • What is the purpose of a boolean?
A

to display whether something is true or false - works as switch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • What does the=operator mean in JavaScript?
A

does not mean equal, means assign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • How do you update the value of a variable?
A

variableName then assign new value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  • What is the difference betweennullandundefined?
A

null is predictable, set by developer… undefined has no value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  • Why is it a good habit to include “labels” when you log values to the browser console?
A

to identify what our log is

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  • Give five examples of JavaScript primitives.
A

string, number, boolean, null, undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  • What data type is returned by an arithmetic operation?
A

number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  • What is string concatenation?
A

adding two strings together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  • What purpose(s) does the+plus operator serve in JavaScript?
A

to add two values, string and string, number and number, or mix

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  • What data type is returned by comparing two values (,===, etc)?
A

boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  • What does the+=”plus-equals” operator do?
A

shorthand operator that adds right operand to left operand and assigns back to left operand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  • What are objects used for?
A

to store information about something

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  • What are object properties?
A

variable in the confines of an object, place to store data that can be accessed
later

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  • Describe object literal notation.
A

{ property: value };

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  • How do you remove a property from an object?
A

delete operator, dot or bracket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
  • What are the two ways to get or update the value of a property??
A

dot notation or bracket notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  • What are arrays used for?
A

to store lists of similar data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
  • Describe array literal notation.
A

declare variable/array then assignment, then opening bracket for array, list properties, closing bracket of array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
* What is the length property of an array?
property that tells how many pieces of data are inside array
26
* How do you calculate the last index of an array?
array.length - 1
27
* What is a function in JavaScript?
set of steps, instructions, code, that does a specific job
28
* Describe the parts of a function definition.
function keyword, optional name, optional parameter, (), {, code to run, return}
29
* Describe the parts of a function call.
function name (arguments)
30
* When comparing them side-by-side, what are the differences between a function call and a function definition?
one has arguments one has parameters, function definition has code block
31
* Why are function parameters useful?
it allows a function to pass information
32
* What two effects does a return statement have on the behavior of a function?
returns data/information and replaces the function call - stops function
33
* What is a method?
methods are functions, property of an object
34
* How is a method different from any other function?
syntax of method and function differs also a method calls on an object
35
* How do you remove the last element from an array?
pop () method
36
* How do you round a number down to the nearest integer?
floor() method
37
* How do you generate a random number?
Math.random() method
38
* How do you delete an element from an array?
splice() method
39
* How do you append an element to an array?
push() method
40
* How do you break a string up into an array?
split () method
41
* Do string methods change the original string? How would you check if you weren't sure?
they don’t, if you want to check, console log it
42
* Is the return value of a function or method useful in every situation?
No
43
* Give 6 examples of comparison operators.
, >=, <=, !, &&, ==
44
* What are the three logical operators?
&& ! ||
45
* What is the purpose of a loop?
to repeat a block of code as necessary
46
* What is the purpose of a condition expression in a loop?
sets the condition as for when the loop should stop
47
* What does "iteration" mean in the context of loops?
each time the code block runs
48
* When does the condition expression of a while loop get evaluated?
before each iteration
49
* When does the initialization expression of a for loop get evaluated?
before the loop begins just once
50
* When does the condition expression of a for loop get evaluated?
before each iteration takes place
51
* When does the final expression of a for loop get evaluated?
after each iteration takes place
52
* Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
53
* What does the ++ increment operator do?
increments value of variable by 1
54
* How do you iterate through the keys of an object?
for in loop
55
* Give two examples of document methods that retrieve a single element from the DOM.
queryselector and getelementbyid
56
* Give one example of a document method that retrieves multiple elements from the DOM at once.
queryselectorall and getelementsbytagname and getelementsbyclassname
57
* What console method allows you to inspect the properties of a DOM element object?
console.dir();
58
* Why would a  tag need to be placed at the bottom of the HTML content instead of at the top?
because html docs load top to bottom, so javascript must be at bottom to retrieve html elements
59
* What does document.querySelector() take as its argument and what does it return?
takes string with css selector and return element node
60
* What does document.querySelectorAll() take as its argument and what does it return
takes string with css selector and returns a novelist
61
* Why do we log things to the console?
for debugging, to log values and variables, and for verification — but for Dom events to check if action happens
62
* Are all possible parameters required to use a JavaScript method or function?
no
63
* What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
64
* What is a callback function?
function passed as an argument for another function
65
* What object is passed into an event listener callback when the event fires?
the event object
66
* What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
the top one waits for the browser to call the function where as the bottom one runs calls the function as soon a page loads
67
* What is the className property of element objects?
allows us to get and set class attribute
68
* How do you update the CSS class attribute of an element using JavaScript?
elementselected.className = ‘class name’
69
* What is the textContent property of element objects?
get or sets text content of element object
70
* How do you update the text within an element using JavaScript?
element.textContent = ‘string’
71
* Is the event parameter of an event listener callback always useful?
no
72
* Why is storing information about a program in variables better than only storing it in the DOM?
variables are easier to work with in javascript - condenses your dom work
73
* What event is fired when a user places their cursor in a form control?
focus
74
* What event is fired when a user's cursor leaves a form control?
blur
75
* What event is fired when a user clicks the "submit" button within a ?
submit
76
* What does the event.preventDefault() method do?
prevents default behavior of event
77
* What does submitting a form without event.preventDefault() do?
refreshes page
78
* What property of a form element object contains all of the form's controls.
elements property
79
* What property of a form control object gets and sets its value?
value property
80
Does the document.createElement() method insert a new element into the page?
It does not, just creates it. Still needs to be assigned or inserted to page.
81
How do you add an element as a child to another element?
parent.appendChild(element)
82
What do you pass as the arguments to the element.setAttribute() method?
setAttrribute(nameofattribute, value)
83
What steps do you need to take in order to insert a new element into the page?
Query the parent element, create a new element, append new element to parent element
84
What is the textContent property of an element object for?
used to set text content for the HTML element or get the text content written inside that element
85
Name two ways to set the class attribute of a DOM element.
setAttribute(name,value) or document.className() method
86
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
reusable
87
What is the event.target?
element where the event originated from
88
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling
89
What DOM element property tells you what type of element it is?
.tagName
90
What does the element.closest() method take as its argument and what does it return?
NEED
91
How can you remove an element from the DOM?
element.remove();
92
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
add event listener to parent
93
What is the event.target?
element that triggered event, where event originated from
94
What is the affect of setting an element to display: none?
element removed from document flow, hides element - no longer visible
95
What does the element.matches() method take as an argument and what does it return?
Takes a css selector thats a string, returns boolean if it matches dom element
96
How can you retrieve the value of an element's attribute?
getAttribute();
97
At what steps of the solution would it be helpful to log things to the console?
At every step
98
If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?
you would have to add event listeners to every new element
99
If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
You'd have to write a condition for each tab
100
What are serialization and deserialization?
serialization: chunk of data that is sequenced deserialization: sequenced row of data that is made easy to use
101
Why are serialization and deserialization useful?
serialization helps make complex data easily transmissible, deserialized data allows us to work with the data more efficiently
102
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify(values), values ie object or array
103
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse(string) method to return object or array
104
How do you store data in localStorage?
localStorage.setItem();
105
How do you retrieve data from localStorage?
localStorage.getItem();
106
What data type can localStorage save in the browser?
strings only
107
When does the 'beforeunload' event fire on the window object?
before the content of the page is loaded
108
What is a method?
a function that’s a property of an object
109
How can you tell the difference between a method definition and a method call?
definition has function with code block where as call does not
110
Describe method definition syntax (structure).
method name, colon, function keyword followed by parameter(s) and code block
111
Describe method call syntax (structure).
object or element period method name parenthesis argument(s) being passed in
112
How is a method different from any other function?
method has a receiver whereas functions don’t
113
What is the defining characteristic of Object-Oriented Programming?
OOP can contain both data and methods as properties
114
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
115
What is "abstraction"?
the process of making something complex simple for our use
116
What does API stand for?
application programming interface
117
What is the purpose of an API?
holds contracts and comm with other applications or computer systems, defines functions and who does what