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
Describe array literal notation.
var varName = [,];
26
How are arrays different from "plain" objects?
arrays have key as index for each value, value in array almost always contain the same type of data, array comes with length property
27
What number represents the first index of an array?
0
28
What is the length property of an array?
amount of items within an array
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
a set of action that is given a name and can be recalled/repeated use
31
Describe the parts of a function definition.
function keyword functionName (parameter/s) { code to do stuff return (optional) }
32
Describe the parts of a function call.
functionName(argument/s);
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
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();
34
What is the difference between a parameter and an argument?
parameter (placeholder) is used when defining function. argument (value) is used when calling the function.
35
Why are function parameters useful?
so that function can be dynamic and have the ability to do more than 1 thing
36
What two effects does a return statement have on the behavior of a function?
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
37
Why do we log things to the console?
debugging, verification
38
What is a method?
functions built into variables
39
How is a method different from any other function?
has to be called from a variable
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()
42
How do you generate a random number?
Math.random()
43
How do you delete an element from an array?
array.splice(starting index, how many item)
44
How do you append an element to an array?
array.push()
45
How do you break a string up into an array?
string.split(separator)
46
Do string methods change the original string? How would you check if you weren't sure?
no, console.log it
47
Is the return value of a function or method useful in every situation?
depends
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
49
Give 6 examples of comparison operators.
<, >, ==, ===, !=, !==, <=, >=
50
What data type do comparison expressions evaluate to?
boolean
51
What is the purpose of an if statement?
a gate keeper to a block of code which only allow access if a condition is met. Make decision within code
52
Is else required in order to use an if statement?
no
53
Describe the syntax (structure) of an if statement.
if (something comparison-operator something) { do something return something }
54
What are the three logical operators?
and, or, not
55
How do you compare two different expressions in the same condition?
&& or ||
56
What is the purpose of a loop?
tools to allow user to do something over and over
57
What is the purpose of a condition expression in a loop?
to break from the loop
58
What does "iteration" mean in the context of loops?
a single repetition of a loop
59
When does the condition expression of a while loop get evaluated?
before each iteration of the code block
60
When does the initialization expression of a for loop get evaluated?
one time 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?
after the code block run
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
65
How do you iterate through the keys of an object
for (const key in obj) -> for...in loop
66
What event is fired when a user places their cursor in a form control?
focus
67
What event is fired when a user's cursor leaves a form control?
blur
68
What event is fired as a user changes the value of a form control?
input
69
What event is fired when a user clicks the "submit" button within a
?
submit
70
What does the event.preventDefault() method do?
prevent the default action of event origin
71
What does submitting a form without event.preventDefault() do?
prevent the form from resetting (web page refresh to clean page with no input values)
72
What property of a form element object contains all of the form's controls.
.elements
73
What property of a form control object gets and sets its value?
.value
74
What is JSON?
text-based data format following JavaScript object syntax
75
What are serialization and deserialization?
the process of taking things in order or out of order
76
Why are serialization and deserialization useful?
shrinking the overall size (easier to transfer), putting things back into a formatted form of data
77
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify(data)
78
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse(data)
79
How do you store data in localStorage?
Storage.setItem(key, value) -- both in 'string'
80
How do you retrieve data from localStorage?
Storage.getItem(key)
81
What data type can localStorage save in the browser?
string
82
When does the 'beforeunload' event fire on the window object?
when the window unloaded (closed, refreshed...)
83
What is a method?
function inside object
84
How can you tell the difference between a method definition and a method call?
assign (:) vs object.method()
85
Describe method definition syntax (structure).
Object.method
86
Describe method call syntax (structure).
Object.method()
87
How is a method different from any other function?
Store inside an object, have to be called through object.method()
88
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
89
What are the four "principles" of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
90
What is "abstraction"?
being able to work with (possibly) complex things in simple ways.
91
What does API stand for?
Application Programming Interface (API)
92
What is the purpose of an API?
way to give programmers to interact with a system in a simplified, consistent fashion
93
What is >this< in JavaScript?
this is an implicit parameter. this holds current object it's inside of
94
What does it mean to say that this is an "implicit parameter"?
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
When is the value of this determined in a function; call time or definition time?
Call time
96
How can you tell what the value of this will be for a particular function or method definition?
can't tell until it is called
97
How can you tell what the value of this is for a particular function or method call?
looking at the object to the left of the dot (.)
98
What kind of inheritance does the JavaScript programming language use?
prototype-based (prototypal)
99
What is a prototype in JavaScript?
a source of data or behavior that get built off of by other things
100
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?
if those variable are linked to the prototype behaviors (methods)
101
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
prototype chain
102
What does the new operator do?
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
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
104
What does the instanceof operator do?
determine whether an object is a variance of another object, return boolean. object instanceof bigger_object
105
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?
setTimeOut()
106
How can you set up a function to be called repeatedly without using a loop?
setInterval()
107
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
108
What do setTimeout() and setInterval() return?
a positive integer value which identifies the timer
109
What does fetch() return?
returning a promise which is fulfilled once the response is available
110
What is the default request method used by fetch()?
GET
111
What must the return value of myFunction be if the following expression is possible? myFunction()();
it has to return a function
112
What does this code do? const wrap = value => () => value;
const wrapped = wrap(value) wrapped() => = value
113
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
when it's called
114
What allows JavaScript functions to "remember" values from their surroundings?
closures
115
what is a closure?
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.