JavaScript Flashcards

1
Q

What is the purpose of variables?

A

a vehicle to have permanence of data

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

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

=

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, number $ and _

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

uppercase =/= lowercase

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 hold 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

for math

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

for conditionals, to make decisions

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

value is being assigned to

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

reassign 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 is an assigned value without value, undefined has never been assigned

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

for context in the output

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

What data type is returned by an arithmetic operation?

A

A number

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

What is string concatenation?

A

joining strings together

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

concatenation or addition

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

boolean

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 multiple variables under one name

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

What are object properties?

A

individual piece of named data within an object

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

Describe object literal notation.

A

var object = {} with commas after each new variable

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

with the delete operator

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 or square bracket notation

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

What is a function in JavaScript?

A

A repeatable set of actions with a specific name

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

Describe the parts of a function definition

A

Function keyword with the name of the function followed by () with optional parameters inside, curly braces with code inside and a return statement to give back a value

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

Describe the parts of a function call

A

Function name, (), with optional arguments inside the parentheses

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

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

A

A function call has just the name with the arguments inside the following parentheses. Whereas the definition has the word function followed by the functions name and parameters inside the parenthesis with a following code block containing a return

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

What is the difference between a parameter and an argument?

A

parameter is in the function definition. argument is the real data being passed to the function

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

Why are function parameters useful?

A

it allows you to have variance in the application of the function

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

Why do we log things to the console?

A

debugging, verification

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

What is a method?

A

A function in an object

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

How is a method different from any other function?

A

Function inside an object rather than by itself. function() vs obj.method()

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

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

A

Math.floor()

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

How do you generate a random number?

A

Math.random()

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

How do you delete an element from an array?

A

splice()

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

How do you append an element to an array?

A

push()

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

How do you break a string up into an array?

A

split()

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

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

A

no, console log to check

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

Give 6 examples of comparison operators.

A

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

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

What data type do comparison expressions evaluate to?

A

boolean

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

What is the purpose of an if statement?

A

allows us to take decisions in our code

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

Is else required in order to use an if statement?

A

no

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

What are the three logical operators?

A

&&, ||, !

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

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

A

and, or

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 be able to do things repeatedly

46
Q

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

A

To create a point in which the loop will stop

47
Q

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

A

Each time the loop runs

48
Q

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

A

before each run

48
Q

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

A

only once before it runs

49
Q

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

A

before each iteration

50
Q

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

A

after each run

51
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

52
Q

What does the ++ increment operator do?

A

increases val of variable by 1

53
Q

How do you iterate through the keys of an object?

A

for in loop

54
Q

What are the four components of “the Cascade”.

A

Source order, specificity, !important, and inheritance

55
Q

What does the term “source order” mean with respect to CSS?

A

the order that css rules are written in the stylesheet

56
Q

How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?

A

inheritance

57
Q

List the three selector types in order of increasing specificity.

A

type, class, ID

58
Q

Why is using !important considered bad practice?

A

Its high specificity makes it hard to overwrite

59
Q

What event is fired when a user places their cursor in a form control?

A

focus

60
Q

What event is fired when a user’s cursor leaves a form control?

A

blur

61
Q

What event is fired as a user changes the value of a form control?

A

input

62
Q

What event is fired when a user clicks the “submit” button within a <form>?

A

submit

63
Q

What does the event.preventDefault() method do?

A

prevents the event from being submitted blank

64
Q

What does submitting a form without event.preventDefault() do?

A

refreshes page with data in url

65
Q

What property of a form element object contains all of the form’s controls.

A

elements

66
Q

What property of a form control object gets and sets its value?

A

value

67
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

you could be writing many bugs

68
Q

What is an advantage of having your console open when writing a JavaScript program?

A

you can see a log after every line of code you write

69
Q

What is JSON?

A

text-based data interchange format based on javascript object syntax

70
Q

What are serialization and deserialization?

A

turning pieces of data into a string of data

71
Q

Why are serialization and deserialization useful?

A

to be able to send data and make it easy to receive

72
Q

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

A

JSON.stringify method

73
Q

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

A

JSON.parse method

74
Q

How do you store data in localStorage?

A

setItem(key, value)

75
Q

How do you retrieve data from localStorage?

A

getItem(key)

76
Q

What data type can localStorage save in the browser?

A

String

77
Q

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

A

before closing the tab

78
Q

What is a method?

A

A function assigned to a property of an object

79
Q

How can you tell the difference between a method definition and a method call?

A

Definition has a function keyword and a code block in assignment, call has a obj name with ()

80
Q

Describe method definition syntax (structure).

A

Function name with : then function keyword and paramteters inside () and a code block

81
Q

Describe method call syntax (structure).

A

object name and dot then method()

82
Q

How is a method different from any other function?

A

it has dot notation

83
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain both data and behavior

84
Q

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

A

abstraction, inheritance, encapsulation, polymorphism

85
Q

What is “abstraction”?

A

simplification for interaction with something complex

86
Q

What does API stand for?

A

application programming interface

87
Q

What is the purpose of an API?

A

allows apps to exchange data and functionality

88
Q

What is this in JavaScript?

A

implicit parameter of all javascript functions, it gives the current object from where the function or method was called

89
Q

What does it mean to say that this is an “implicit parameter”?

A

parameter that is given to all functions, and not listen in the parameter list

90
Q

When is the value of this determined in a function; call time or definition time?

A

call time

91
Q

How can you tell what the value of this will be for a particular function or method definition?

A

You can’t unless its called

92
Q

How can you tell what the value of this is for a particular function or method call?

A

by seeing where it was called from

93
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance

94
Q

What is a prototype in JavaScript?

A

an object with shared behavior or data that can be stored in one place and shared by all created instances

95
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

because they have assigned prototypes with those methods

96
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

through its prototypal chain, one layer at a time

97
Q

What does the new operator do?

A

Makes a new blank object with preset prototypes

98
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

the prototype property

99
Q

What does the instanceof operator do?

A

Tests if the prototype constructor is anywhere in the chain for the object

100
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout()

101
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

102
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0ms

103
Q

What do setTimeout() and setInterval() return?

A

an ID for the specific timer

104
Q

What is AJAX?

A

building webpages using XMLHttpRequest to dynamically update

105
Q

What does the AJAX acronym stand for?

A

Async javascript and XML

106
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest

107
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

the load event

108
Q

What is the JavaScript Event Loop?

A

part of the runtime that pushes async requests to the call stack when the call stack is clear

109
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

no other code can run until the blocking code completes running