JavaScript Flashcards

1
Q

What is the purpose of variables?

A

it can stores bits of information and can be reuse/recall at later time

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) nameOfVariable;

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

nameOfVariable = value;

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, numbers, dollar sign($) and underscore(_)

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

same variable name with uppercase letter will result in another variable

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/character) letter, word or sentence

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 handle calculation or any tools that utilizes number

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

to define whether something is true or false (for making decision)

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

Assigning / defining

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

by setting the variable to a 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 = nonexistent or invalid value
Undefined = variable without value(argument)
Null = purposeful emptiness
Undefined = accidental emptiness

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

because console.log only return value and it can be hard to keep track which variable it belongs to

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, symbol, BigInt

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

adding second string(argument) behind the first string(argument)

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

mathematic + or concatenation

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 does the += “plus-equals” operator do?

A

x += y -> x = x + y
Number + boolean = number
Number + string = string
Number + number = number
string + string = string
string + boolean = string
boolean + boolean = number

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

What are objects used for?

A

group together variables and function that are related

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

What are object properties?

A

variable & value [key], individual pieces of name and data

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

Describe object literal notation.

A

var varName = { (property) var: value, var2: value, (method) key: function }

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 object.key

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

object.key or object[‘key’]

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

What are arrays used for?

A

to store list of data/information

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

Describe array literal notation.

A

var varName = [,];

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 have key as index for each value,
value in array almost always contain the same type of data,
array comes with length property

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

amount of items within an 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.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 set of action that is given a name and can be recalled/repeated use

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 keyword functionName (parameter/s) {
code to do stuff
return (optional)
}

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(argument/s);

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

definition define what the function do/return which include many parts. Function call actually run the function and can expect result, only contain name of the function plus parenthesis -> functionName();

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

parameter (placeholder) is used when defining function. argument (value) is used when calling the function.

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

Why are function parameters useful?

A

so that function can be dynamic and have the ability to do more than 1 thing

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 can assign result of the function (a value) to a variable that can be used at later time without calling the function again. Another effect is return also exit the function code block

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

debugging, verification

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

What is a method?

A

functions built into variables

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

has to be called from a variable

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()

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

How do you delete an element from an array?

A

array.splice(starting index, how many item)

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

How do you append an element to an array?

A

array.push()

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

How do you break a string up into an array?

A

string.split(separator)

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

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

A

no, console.log it

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

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

A

depends

48
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

49
Q

Give 6 examples of comparison operators.

A

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

50
Q

What data type do comparison expressions evaluate to?

A

boolean

51
Q

What is the purpose of an if statement?

A

a gate keeper to a block of code which only allow access if a condition is met. Make decision within code

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 (something comparison-operator something) {
do something
return something
}

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

&& or ||

56
Q

What is the purpose of a loop?

A

tools to allow user to do something over and over

57
Q

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

A

to break from the loop

58
Q

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

A

a single repetition of a loop

59
Q

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

A

before each iteration of the code block

60
Q

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

A

one time 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

after the code block run

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

65
Q

How do you iterate through the keys of an object

A

for (const key in obj) -> for…in loop

66
Q

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

A

focus

67
Q

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

A

blur

68
Q

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

A

input

69
Q

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

A

submit

70
Q

What does the event.preventDefault() method do?

A

prevent the default action of event origin

71
Q

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

A

prevent the form from resetting (web page refresh to clean page with no input values)

72
Q

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

A

.elements

73
Q

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

A

.value

74
Q

What is JSON?

A

text-based data format following JavaScript object syntax

75
Q

What are serialization and deserialization?

A

the process of taking things in order or out of order

76
Q

Why are serialization and deserialization useful?

A

shrinking the overall size (easier to transfer), putting things back into a formatted form of data

77
Q

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

A

JSON.stringify(data)

78
Q

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

A

JSON.parse(data)

79
Q

How do you store data in localStorage?

A

Storage.setItem(key, value) – both in ‘string’

80
Q

How do you retrieve data from localStorage?

A

Storage.getItem(key)

81
Q

What data type can localStorage save in the browser?

A

string

82
Q

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

A

when the window unloaded (closed, refreshed…)

83
Q

What is a method?

A

function inside object

84
Q

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

A

assign (:) vs object.method()

85
Q

Describe method definition syntax (structure).

A

Object.method

86
Q

Describe method call syntax (structure).

A

Object.method()

87
Q

How is a method different from any other function?

A

Store inside an object, have to be called through object.method()

88
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods).

89
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

90
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways.

91
Q

What does API stand for?

A

Application Programming Interface (API)

92
Q

What is the purpose of an API?

A

way to give programmers to interact with a system in a simplified, consistent fashion

93
Q

What is >this< in JavaScript?

A

this is an implicit parameter.
this holds current object it’s inside of

94
Q

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

A

meaning it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var.
Doesn’t exist until it is called upon (function is called)

95
Q

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

A

Call time

96
Q

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

A

can’t tell until it is called

97
Q

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

A

looking at the object to the left of the dot (.)

98
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (prototypal)

99
Q

What is a prototype in JavaScript?

A

a source of data or behavior that get built off of by other things

100
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

if those variable are linked to the prototype behaviors (methods)

101
Q

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

A

prototype chain

102
Q

What does the new operator do?

A

create a new user-defined object.
create a blank, plain javascript object.
takes value of the prototype value from function invoked.
execute the constructor function.
return from function.

103
Q

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

A

prototype

104
Q

What does the instanceof operator do?

A

determine whether an object is a variance of another object, return boolean.
object instanceof bigger_object

105
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()

106
Q

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

A

setInterval()

107
Q

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

A

0

108
Q

What do setTimeout() and setInterval() return?

A

a positive integer value which identifies the timer

109
Q

What does fetch() return?

A

returning a promise which is fulfilled once the response is available

110
Q

What is the default request method used by fetch()?

A

GET

111
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

it has to return a function

112
Q

What does this code do?
const wrap = value => () => value;

A

const wrapped = wrap(value)
wrapped() => = value

113
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it’s called

114
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closures

115
Q

what is a closure?

A

closure is a protected scope, it maintain memory/reference to its lexical scope. This environment consists of any local variables that were in-scope at the time the closure was created.