JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Give the browser a short term memory of certain bits. to use later on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you declare a variable?

A

var keyword: var name = var value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you initialize (assign a value to) a variable?

A
var name = value;
use single equal signs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What characters are allowed in variable names?

A

letters and dollar signs and underscore and number but you cant start with number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does it mean to say that variable names are “case sensitive”?

A

lower and upper cases matter (cats is not the same as Cats)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of a string?

A

to store text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of a number?

A

to store numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of a boolean?

A

give data either true or false. logic with binary state, on/off

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the = operator mean in JavaScript?

A

assignment operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you update the value of a variable?

A

variable name = new value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between null and undefined?

A

null if intentional missing of data where as undefined is missing where its suppose to be

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why is it a good habit to include “labels” when you log values to the browser console?

A

to know which variables if logging and which is not to make it easier to debug code and read.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Give five examples of JavaScript primitives.

A

Number, null, undefined, Boolean, string, array , object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
Q

What is string concatenation?

A

the process of combining multiply strings into one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What purpose(s) does the + plus operator serve in JavaScript?

A

additions in numeric values or concationate strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What data type is returned by comparing two values (, ===, etc)?

A

Booleons

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the += “plus-equals” operator do?

A

it add the data to the variables and set the new value as the variables
(num = num + 10 is the same num += 10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are objects used for?

A

a group or set of variables and function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are object properties?

A

variables but they are apart of the object (boundaries)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Describe object literal notation.

A

opening brace and then properties then value then closing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you remove a property from an object?

A

delete operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
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
24
Q

What are arrays used for?

A

store lists of values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
[ value1, value2, value3]
26
How are arrays different from "plain" objects?
arrays are object with index numbers as the properties
27
What number represents the first index of an array?
0
28
What is the length property of an array?
count how many items is in the array.
29
How do you calculate the last index of an array?
array[array.length -1]
30
What is a function in JavaScript?
a block of rerunnable code that have a specific instructions on how to do certain task.
31
Describe the parts of a function definition.
``` function functionName(parameters separating by comma) { code block return } ```
32
Describe the parts of a function call.
functionName(arguements)
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition have the syntax function leading and the code block. whereas the calling only have the function names and its specific arguements.
34
What is the difference between a parameter and an argument?
parameters is to setup the function. arguement is the value for that certain case being use by the function. parameter is for defining argument is for calling
35
Why are function parameters useful?
It let you access data and automate things that you other wise cannot do.
36
What two effects does a return statement have on the behavior of a function?
it gives the function a result value. | and it stops the function from continuing once a return is run.
37
Why do we log things to the console?
To check the output of the code
38
What is a method?
a function which is a properies of an object.
39
How is a method different from any other function
it is a part of an object
40
How do you remove the last element from an array?
array.pop
41
How do you round a number down to the nearest integer?
Math.floor(number)
42
How do you generate a random number?
Math.random()
43
How do you delete an element from an array?
array.splice(location, how many object)
44
How do you appned an elemnnt to an array
array.push()
45
How do you break a string up into an array?
string.split(breaker)
46
Do string methods change the origin string? How would you check if you weren't sure?
no it does not string is not changable! you can log the original string
47
is the return value of a function or method useful in every situation?
no
48
what three-letter acronym should you always include in google search about javascript or css?q
mdn
49
Give 6 examples of comparison operators.
``` strictly equal === equal == less than < more than > not equal != not strictly equal !== ```
50
What data type do comparison expressions evaluate to?
Booleons
51
What is the purpose of an if statement?
to make decisions.
52
Is else required in order to use an if statement?
no
53
Describe the syntax (structure) of an if statement.
``` if (conditions) { codeblock } else { codeblock } ```
54
What are the three logical operators?
and && or || not !
55
How do you compare two different expressions in the same condition?
logical operators
56
What is the purpose of a loop?
to repeat codes if a certain condition is met
57
What is the purpose of a condition expression in a loop?
to tell the loop when and where to stop true condition you run the loop again false condition you stop the code
58
What does "iteration" mean in the context of loops?
repetition of code blocj
59
When does the condition expression of a while loop get evaluated?
before the code block run
60
When does the initialization expression of a for loop get evaluated?
the very begining. happen once before everything else
61
When does the condition expression of a for loop get evaluated?
before each iteration
62
When does the final expression of a for loop get evaluated?
at the end of each iteration before condition
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
64
What does the ++ increment operator do?
add 1 to the variable and signed it to the variable
65
How do you iterate through the keys of an object?
for in loop
66
Why do we log things to the console?
to check if the output matches out expectation of it.
67
What is a "model"?
some thing that should be follow. like a blueprint | Representation
68
Which "document" is being referred to in the phrase Document Object Model?
HTML
69
What is the word "object" referring to in the phrase Document Object Model?
JavaScript
70
What is a DOM Tree?
An html element with all of its childrens and attributes
71
Give two examples of document methods that retrieve a single element from the DOM.
querySelect() and getElementById()
72
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectAll
73
Why might you want to assign the return value of a DOM query to a variable?
so that you could reuse the variable to target that element
74
What console method allows you to inspect the properties of a DOM element object?
console.dir
75
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
so that all the html get loaded first so that all the dom selectors can work
76
What does document.querySelector() take as its argument and what does it return?
css selectors
77
What does document.querySelectorAll() take as its argument and what does it return?
css selectors for all the element
78
What is the purpose of events and event handling?
interactive sites that response if the user or the document did something
79
Are all possible parameters required to use a JavaScript method or function?
no
80
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener('type of event', 'the function to call without () becuase you are not calling it)
81
What is a callback function?
function that you will call back later
82
What object is passed into an event listener callback when the event fires?
the element
83
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
the element that the event happen on ie maybe something someone clicked one console.log and console.dir
84
What is the className property of element objects?
get the classes on that object and give you the ability to change it
85
How do you update the CSS class attribute of an element using JavaScript?
classList.add('classname') | className = 'classname'
86
What is the textContent property of element objects?
the text that html is showing for each element
87
How do you update the text within an element using JavaScript?
element.textContent = 'New TEXT'
88
Is the event parameter of an event listener callback always useful?
no
89
Why is storing information about a program in variables better than only storing it in the DOM?
put javascript in control of the functions and data instead of DOM
90
Does the document.createElement() method insert a new element into the page?
no it just create the element
91
How do you add an element as a child to another element?
parent.appendChild(child)
92
What do you pass as the arguments to the element.setAttribute() method?
('the atrribute", 'value
93
What steps do you need to take in order to insert a new element into the page?
create the element changes the element add the element (appendchild)
94
What is the textContent property of an element object for?
to change what the element text is in the html
95
Name two ways to set the class attribute of a DOM element.
classList className setAttribute
96
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
it give you the ability to name a chunk of code to something easier to understand it also give the ability to be reuse at anytime
97
Why is it possible to listen for events on one element that actually happen its descendent elements?
due to the layout if you click the children you must clicked the parents
98
What DOM element property tells you what type of element it is?
target.tagName
99
What does the element.closest() method take as its argument and what does it return?
css selectors
100
How can you remove an element from the DOM?
remove()
101
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 an event listener to the parent