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
Q

Describe array literal notation.

A

[ value1, value2, value3]

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

How are arrays different from “plain” objects?

A

arrays are object with index numbers as the properties

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

count how many items is in the array.

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

How do you calculate the last index of an array?

A

array[array.length -1]

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

What is a function in JavaScript?

A

a block of rerunnable code that have a specific instructions on how to do certain task.

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

Describe the parts of a function definition.

A
function functionName(parameters separating by comma) {
code block
return
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Describe the parts of a function call.

A

functionName(arguements)

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

function definition have the syntax function leading and the code block. whereas the calling only have the function names and its specific arguements.

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

What is the difference between a parameter and an argument?

A

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

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

Why are function parameters useful?

A

It let you access data and automate things that you other wise cannot do.

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

What two effects does a return statement have on the behavior of a function?

A

it gives the function a result value.

and it stops the function from continuing once a return is run.

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

Why do we log things to the console?

A

To check the output of the code

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

What is a method?

A

a function which is a properies of an object.

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

How is a method different from any other function

A

it is a part of an object

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

How do you remove the last element from an array?

A

array.pop

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

How do you round a number down to the nearest integer?

A

Math.floor(number)

42
Q

How do you generate a random number?

A

Math.random()

43
Q

How do you delete an element from an array?

A

array.splice(location, how many object)

44
Q

How do you appned an elemnnt to an array

A

array.push()

45
Q

How do you break a string up into an array?

A

string.split(breaker)

46
Q

Do string methods change the origin string? How would you check if you weren’t sure?

A

no it does not string is not changable! you can log the original string

47
Q

is the return value of a function or method useful in every situation?

A

no

48
Q

what three-letter acronym should you always include in google search about javascript or css?q

A

mdn

49
Q

Give 6 examples of comparison operators.

A
strictly equal ===
equal ==
less than <
more than >
not equal !=
not strictly equal !==
50
Q

What data type do comparison expressions evaluate to?

A

Booleons

51
Q

What is the purpose of an if statement?

A

to make decisions.

52
Q

Is else required in order to use an if statement?

A

no

53
Q

Describe the syntax (structure) of an if statement.

A
if (conditions) {
codeblock
} else {
codeblock
}
54
Q

What are the three logical operators?

A

and &&
or ||
not !

55
Q

How do you compare two different expressions in the same condition?

A

logical operators

56
Q

What is the purpose of a loop?

A

to repeat codes if a certain condition is met

57
Q

What is the purpose of a condition expression in a loop?

A

to tell the loop when and where to stop
true condition you run the loop again
false condition you stop the code

58
Q

What does “iteration” mean in the context of loops?

A

repetition of code blocj

59
Q

When does the condition expression of a while loop get evaluated?

A

before the code block run

60
Q

When does the initialization expression of a for loop get evaluated?

A

the very begining. happen once before everything else

61
Q

When does the condition expression of a for loop get evaluated?

A

before each iteration

62
Q

When does the final expression of a for loop get evaluated?

A

at the end of each iteration before condition

63
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

64
Q

What does the ++ increment operator do?

A

add 1 to the variable and signed it to the variable

65
Q

How do you iterate through the keys of an object?

A

for in loop

66
Q

Why do we log things to the console?

A

to check if the output matches out expectation of it.

67
Q

What is a “model”?

A

some thing that should be follow. like a blueprint

Representation

68
Q

Which “document” is being referred to in the phrase Document Object Model?

A

HTML

69
Q

What is the word “object” referring to in the phrase Document Object Model?

A

JavaScript

70
Q

What is a DOM Tree?

A

An html element with all of its childrens and attributes

71
Q

Give two examples of document methods that retrieve a single element from the DOM.

A

querySelect() and getElementById()

72
Q

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

querySelectAll

73
Q

Why might you want to assign the return value of a DOM query to a variable?

A

so that you could reuse the variable to target that element

74
Q

What console method allows you to inspect the properties of a DOM element object?

A

console.dir

75
Q

Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?

A

so that all the html get loaded first so that all the dom selectors can work

76
Q

What does document.querySelector() take as its argument and what does it return?

A

css selectors

77
Q

What does document.querySelectorAll() take as its argument and what does it return?

A

css selectors for all the element

78
Q

What is the purpose of events and event handling?

A

interactive sites that response if the user or the document did something

79
Q

Are all possible parameters required to use a JavaScript method or function?

A

no

80
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener(‘type of event’, ‘the function to call without () becuase you are not calling it)

81
Q

What is a callback function?

A

function that you will call back later

82
Q

What object is passed into an event listener callback when the event fires?

A

the element

83
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

the element that the event happen on ie maybe something someone clicked one
console.log and console.dir

84
Q

What is the className property of element objects?

A

get the classes on that object and give you the ability to change it

85
Q

How do you update the CSS class attribute of an element using JavaScript?

A

classList.add(‘classname’)

className = ‘classname’

86
Q

What is the textContent property of element objects?

A

the text that html is showing for each element

87
Q

How do you update the text within an element using JavaScript?

A

element.textContent = ‘New TEXT’

88
Q

Is the event parameter of an event listener callback always useful?

A

no

89
Q

Why is storing information about a program in variables better than only storing it in the DOM?

A

put javascript in control of the functions and data instead of DOM

90
Q

Does the document.createElement() method insert a new element into the page?

A

no it just create the element

91
Q

How do you add an element as a child to another element?

A

parent.appendChild(child)

92
Q

What do you pass as the arguments to the element.setAttribute() method?

A

(‘the atrribute”, ‘value

93
Q

What steps do you need to take in order to insert a new element into the page?

A

create the element
changes the element
add the element (appendchild)

94
Q

What is the textContent property of an element object for?

A

to change what the element text is in the html

95
Q

Name two ways to set the class attribute of a DOM element.

A

classList
className
setAttribute

96
Q

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

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
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

due to the layout if you click the children you must clicked the parents

98
Q

What DOM element property tells you what type of element it is?

A

target.tagName

99
Q

What does the element.closest() method take as its argument and what does it return?

A

css selectors

100
Q

How can you remove an element from the DOM?

A

remove()

101
Q

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?

A

add an event listener to the parent