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
Q
  • What is thelengthproperty of an array?
A

property that tells how many pieces of data are inside array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
  • How do you calculate the last index of an array?
A

array.length - 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
  • What is a function in JavaScript?
A

set of steps, instructions, code, that does a specific job

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q
  • Describe the parts of a functiondefinition.
A

function keyword, optional name, optional parameter, (), {, code to run, return}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q
  • Describe the parts of a functioncall.
A

function name (arguments)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
  • When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
A

one has arguments one has parameters, function definition has code block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
  • Why are functionparametersuseful?
A

it allows a function to pass information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
  • What two effects does areturnstatement have on the behavior of a function?
A

returns data/information and replaces the function call - stops function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
  • What is a method?
A

methods are functions, property of an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
  • How is a method different from any other function?
A

syntax of method and function differs also a method calls on an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q
  • How do you remove the last element from an array?
A

pop () method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q
  • How do you round a number down to the nearest integer?
A

floor() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q
  • How do you generate a random number?
A

Math.random() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q
  • How do you delete an element from an array?
A

splice() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q
  • How do you append an element to an array?
A

push() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q
  • How do you break a string up into an array?
A

split () method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q
  • Do string methods change the original string? How would you check if you weren’t sure?
A

they don’t, if you want to check, console log it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q
  • Is the return value of a function or method useful in every situation?
A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q
  • Give 6 examples of comparison operators.
A

, >=, <=, !, &&, ==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q
  • What are the three logical operators?
A

&& ! ||

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

to repeat a block of code as necessary

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

sets the condition as for when the loop should stop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q
  • What does “iteration” mean in the context of loops?
A

each time the code block runs

48
Q
  • Whendoes theconditionexpression of awhileloop get evaluated?
A

before each iteration

49
Q
  • Whendoes theinitializationexpression of aforloop get evaluated?
A

before the loop begins just once

50
Q
  • Whendoes theconditionexpression of aforloop get evaluated?
A

before each iteration takes place

51
Q
  • Whendoes thefinalexpression of aforloop get evaluated?
A

after each iteration takes place

52
Q
  • Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?
A

break

53
Q
  • What does the++increment operator do?
A

increments value of variable by 1

54
Q
  • How do you iterate through the keys of an object?
A

for in loop

55
Q
  • Give two examples ofdocumentmethods that retrieve a single element from the DOM.
A

queryselector and getelementbyid

56
Q
  • Give one example of adocumentmethod that retrieves multiple elements from the DOM at once.
A

queryselectorall and getelementsbytagname and getelementsbyclassname

57
Q
  • Whatconsolemethod allows you to inspect the properties of a DOM element object?
A

console.dir();

58
Q
  • Why would atag need to be placed at the bottom of the HTML content instead of at the top?
A

because html docs load top to bottom, so javascript must be at bottom to retrieve html elements

59
Q
  • What doesdocument.querySelector()take as its argument and what does it return?
A

takes string with css selector and return element node

60
Q
  • What doesdocument.querySelectorAll()take as its argument and what does it return
A

takes string with css selector and returns a novelist

61
Q
  • Why do we log things to the console?
A

for debugging, to log values and variables, and for verification — but for Dom events to check if action happens

62
Q
  • Are all possible parameters required to use a JavaScript method or function?
A

no

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

addEventListener

64
Q
  • What is a callback function?
A

function passed as an argument for another function

65
Q
  • What object is passed into an event listener callback when the event fires?
A

the event object

66
Q
  • What is the difference between these two snippets of code?
    element. addEventListener(‘click’, handleClick)
    element. addEventListener(‘click’, handleClick())
A

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
Q
  • What is theclassNameproperty of element objects?
A

allows us to get and set class attribute

68
Q
  • How do you update the CSS class attribute of an element using JavaScript?
A

elementselected.className = ‘class name’

69
Q
  • What is thetextContentproperty of element objects?
A

get or sets text content of element object

70
Q
  • How do you update the text within an element using JavaScript?
A

element.textContent = ‘string’

71
Q
  • Is theeventparameter of an event listener callback always useful?
A

no

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

variables are easier to work with in javascript - condenses your dom work

73
Q
  • What event is fired when a user places their cursor in a form control?
A

focus

74
Q
  • What event is fired when a user’s cursor leaves a form control?
A

blur

75
Q
  • What event is fired when a user clicks the”submit”button within a?
A

submit

76
Q
  • What does theevent.preventDefault()method do?
A

prevents default behavior of event

77
Q
  • What does submitting a form withoutevent.preventDefault()do?
A

refreshes page

78
Q
  • What property of a form element object contains all of the form’s controls.
A

elements property

79
Q
  • What property of a form control object gets and sets its value?
A

value property

80
Q

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

A

It does not, just creates it. Still needs to be assigned or inserted to page.

81
Q

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

A

parent.appendChild(element)

82
Q

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

A

setAttrribute(nameofattribute, value)

83
Q

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

A

Query the parent element, create a new element, append new element to parent element

84
Q

What is the textContent property of an element object for?

A

used to set text content for the HTML element or get the text content written inside that element

85
Q

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

A

setAttribute(name,value) or document.className() method

86
Q

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

A

reusable

87
Q

What is the event.target?

A

element where the event originated from

88
Q

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

A

event bubbling

89
Q

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

A

.tagName

90
Q

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

A

NEED

91
Q

How can you remove an element from the DOM?

A

element.remove();

92
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 event listener to parent

93
Q

What is the event.target?

A

element that triggered event, where event originated from

94
Q

What is the affect of setting an element to display: none?

A

element removed from document flow, hides element - no longer visible

95
Q

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

A

Takes a css selector thats a string, returns boolean if it matches dom element

96
Q

How can you retrieve the value of an element’s attribute?

A

getAttribute();

97
Q

At what steps of the solution would it be helpful to log things to the console?

A

At every step

98
Q

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?

A

you would have to add event listeners to every new element

99
Q

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?

A

You’d have to write a condition for each tab

100
Q

What are serialization and deserialization?

A

serialization: chunk of data that is sequenced
deserialization: sequenced row of data that is made easy to use

101
Q

Why are serialization and deserialization useful?

A

serialization helps make complex data easily transmissible, deserialized data allows us to work with the data more efficiently

102
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify(values), values ie object or array

103
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse(string) method to return object or array

104
Q

How do you store data in localStorage?

A

localStorage.setItem();

105
Q

How do you retrieve data from localStorage?

A

localStorage.getItem();

106
Q

What data type can localStorage save in the browser?

A

strings only

107
Q

When does the ‘beforeunload’ event fire on the window object?

A

before the content of the page is loaded

108
Q

What is amethod?

A

a function that’s a property of an object

109
Q

How can you tell the difference between a methoddefinitionand a methodcall?

A

definition has function with code block where as call does not

110
Q

Describe methoddefinitionsyntax (structure).

A

method name, colon, function keyword followed by parameter(s) and code block

111
Q

Describe methodcallsyntax (structure).

A

object or element period method name parenthesis argument(s) being passed in

112
Q

How is a method different from any other function?

A

method has a receiver whereas functions don’t

113
Q

What is thedefining characteristicof Object-Oriented Programming?

A

OOP can contain both data and methods as properties

114
Q

What are the four “principles” of Object-Oriented Programming?

A

abstraction, encapsulation, inheritance, polymorphism

115
Q

What is “abstraction”?

A

the process of making something complex simple for our use

116
Q

What does API stand for?

A

application programming interface

117
Q

What is the purpose of an API?

A

holds contracts and comm with other applications or computer systems, defines functions and who does what