JavaScript Flashcards

1
Q

What is the purpose of variables?

A

assign values

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

How do you declare a variable?

A

use var, let, const

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

How do you initialize a variable?

A

equal sign

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

What characters are allowed in variables names?

A

must begin with a letter, dollar sign, or underscore
can contain numbers but cannot use a dash or period
cannot use keywords or reserved words
case sensitive

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

What dose it mean to say that variable names are case sensitive?

A

if two variables are spelled the same way but have different casing, then js treats them as two different variables

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 characters

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

to store something as true or false

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

What does the = equals sign operator mean in JS

A

assign a variable

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

you use the equal sign operator again

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

a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address

a variable is undefined when a value is not assigned to it

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

This will allow you to see if what you are storing is good and makes sense

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, undefined, symbol, null

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

combining 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 JS?

A

addition, incrementing, 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-equal” operator do?

A

adding or concatenating something to itself

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

What are objects used for?

A

store multiple types of data

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

What are object properties?

A

object properties are the keys of data that are stored in an object

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

Describe object literal notation

A

declare a variable, assignment operator, curly brackets

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 objects?

A

use delete function

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

ordered lists and groupings of information

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

Describe array literal notation

A

square brackets

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

ordered, use index

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

can be called to find the length of 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.length-1

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

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

A

returns a value and exits code block

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

Why are function parameters useful?

A

allows functions to run with certain values

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

What is the difference between a parameter and an argument?

A

parameter is for defining, argument for calling

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 has function keyword and {}

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

Describe the parts of a function call.

A

function call consists of function name and parentheses and possible arguments

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

Describe the parts of a function definition.

A

function keyword, function name, parentheses, possible parameters, {}

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

What is a function in JavaScript?

A

code that can be repeated over and over again easily

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

so that we can see that things are being input correctly

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

What is a method?

A

a function that is a property 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

functions themselves are objects, so a method is actually an object reference to a function

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

pop method

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

floor method

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

random method

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

splice method

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

push or unshift (prepend) method

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

split method

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

mdn, console log, they do not

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

Roughly how many string methods are there according to the MDN Web docs?

A

a lot

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

Roughly how many array methods are there according to the MDN Web docs?

A

a lot

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

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

A

mdn

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

Give 6 examples of comparison operators

A

there is the equal to, less than, greater than, strictly equal to, less than or equal to, and greater than or equal to

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

What is the purpose of an if statement?

A

to make a decision

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

Describe the syntax of an if statement

A

if statement, () with conditionals inside, {} with rule to run if conditions are met

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

What are the three logical operators?

A

logical and, logical or, logical not

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

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

A

use logical and or logical or

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

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

A

after the initialization, and at the beginning of every loop

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

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

A

you loop and then add something to count up

59
Q

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

A

to see if you continue looping

60
Q

What is the purpose of a loop?

A

to perform actions over and over again

61
Q

How do you iterate through the keys of an object?

A

for in loops

62
Q

What does the ++ increment operator do?

A

increment by 1

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

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

A

just before the condition is met

65
Q

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

A

beginning of the loop

66
Q

What is the event.target?

A

the object of the element that the event had happened to

67
Q

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

A

removes from document flow

68
Q

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

A

takes in a string and returns a boolean

69
Q

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

A

getAttribute()

70
Q

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

A

when you assign variables

71
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 include many more event listeners

72
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 would have to include many more if statements

73
Q

What is JSON?

A

json is a string whose format resembles an object literal format

74
Q

What are serialization and deserialization?

A

serialization is making objects into strings and deserialization is the reverse

75
Q

Why are serialization and deserialization useful?

A

converting to json and back

76
Q

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

A

stringify

77
Q

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

A

parse

78
Q

How do you store data in localStorage?

A

you can store data in localStorage by storage.setItem() method

79
Q

How do you retrieve data from localStorage?

A

use storage.getItem() method

80
Q

What data type can localStorage save in the browser?

A

JSON strings

81
Q

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

A

when the window, the document, and its resources are about to be unloaded

82
Q

What is a method?

A

a method is a function which is a property of an object

83
Q

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

A

a method will be defined within an object, similar to a function while a method is called with an object. and then the method name and the ()

84
Q

Describe method definition syntax (structure).

A
var object = {
method: function (parameter) {
do something;
}
}
85
Q

Describe method call syntax (structure).

A

object.method(argument);

86
Q

How is a method different from any other function?

A

it is a property of an object

87
Q

What is the defining characteristic of Object-Oriented Programming?

A

it is based on the concept of objects which contain data and code

88
Q

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

A

abstraction, encapsulation, inheritance, and polymorphism

89
Q

What is “abstraction”?

A

abstraction is modeling and simplifies things for us

90
Q

What does API stand for?

A

application programming interface

91
Q

What is the purpose of an API?

A

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

92
Q

What is this in JavaScript?

A

this is an implicit parameter that uses the object that it is attached to

93
Q

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

A

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

94
Q

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

A

call time

95
Q
What does this refer to in the following code snippet? 
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
A

the object character

96
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

message will be logged to the console with string:

‘It’s-a-me, Mario!’

97
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

you are essentially calling this.firstName on something that does not have a first name property so it returns undefined

98
Q

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

A

cannot be sure

99
Q

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

A

left of the dot

100
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance

101
Q

What is a prototype in JavaScript?

A

prototypes are the mechanism by which javascript objects inherit features from one another; it is a template object that it inherits methods and properties from

102
Q

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

A

use prototype objects to assign those things to them

103
Q

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

A

in the object __proto__

104
Q

What does the new operator do?

A

creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function

105
Q

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

A

prototype

106
Q

What does the instanceof operator do?

A

it tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

107
Q

What is a “callback” function?

A

A callback function is a function passed into another function which is then invoked inside the outer function to complete some kind of routine or action; often used for asynchronous operations

108
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

use the setTimeout() function

109
Q

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

A

use setInterval() function

110
Q

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

A

0

111
Q

What do setTimeout() and setInterval() return?

A

setTimeout() returns a positive integer value which identifies the timer created by the call to setTimeout()

setInterval() returns a numeric, non-zero value which identifies the timer createdby the call to setInterval()

112
Q

What is a code block? What are some examples of a code block?

A
A code block is a group of statements that are delimited by a pair of curly brackets
if (condition) {
   // this is a block and will run code in this block if the statement is met
}
113
Q

What does block scope mean?

A

things exist only within the space of the code block; things that are created within the block scope can only be accessed within the block scope

114
Q

What is the scope of a variable declared with const or let?

A

they are block scoped

115
Q

What is the difference between let and const?

A

let can be reassigned while const creates only a read-only reference to a value and this reference cannot be reassigned but the value can be changed

116
Q

Why is it possible to .push() a new value into a const variable that points to an array?

A

only the reference cannot be changed but the value that is being point at can be changed

117
Q

How should you decide on which type of declaration to use?

A

are you going to be reassigning variables? use let. if not then use const

118
Q

What is the syntax for writing a template literal?

A

instead of using single quotes or double quotes, a template literal uses backticks

119
Q

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions which is also called string formatting

120
Q

What is destructuring, conceptually?

A

Breaking down into individual pieces

121
Q

What is the syntax for object destructuring?

A

var { property, property: variableNameYouWant } = obj

122
Q

What is the syntax for array destructuring?

A

const [ firstIndexToCopy, secondIndexToCopy, , fourthIndexToCopy ] = arr

123
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

One uses {} and the other uses []

also, object literals does not need to consider any indexes or empty indexes while you need to account for them in the array literals

124
Q

What is the syntax for defining an arrow function?

A

if there are no parameters or multiple parameters, you need parentheses but if there is only one parameter, you can omit them
arrow function keyword is necessary
curly brackets are necessary if you are using statements and not just expressions

() => { return x }

125
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

does not return anything

126
Q

How is the value of this determined within an arrow function?

A

at definition time

127
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

128
Q

How do you handle the fulfillment of a Promise?

A

use a then statement

129
Q

How do you handle the rejection of a Promise?

A

use the optional argument of a then statement or a catch statement

130
Q

What is Array.prototype.filter useful for?

A

it is selective for the elements in your array

131
Q

What is Array.prototype.map useful for?

A

Making adjustments to all the elements in your array

132
Q

What is “syntactic sugar”?

A

syntactic sugar is syntax within a programming language to make things easier to read or to express;
makes it easier for the programmer to accomplish certain or to make existing language more intuitive

133
Q

What is the typeof an ES6 class?

A

it is a function

134
Q

Describe ES6 class syntax.

A
class className {
   constructor (name) {
     this.name = name
   }

getName() {
return this.name;
}
}

135
Q

What is “refactoring”?

A

refactoring is the process of restructuring existing computer code without changing its external behavior; in line with syntactic sugar in making things more intuitive and efficient for the programmer

136
Q

How are ES Modules different from CommonJS modules?

A

different syntax, static, has direct support for asynchronous loading and configurable module loading

137
Q

What kind of modules can Webpack support?

A

ecmascript, commonjs, amd, assets, webassembly

138
Q

What does fetch() return?

A

fetch returns a promise for a response at all;

fetch only fails if you spell it wrong or if you have no internet connection

139
Q

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

A

get

140
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

in the optional arguments

141
Q

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

A

it returns a function

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

wrap is being assigned an anonymous function that takes a value as a parameter and then returns a function that has no parameters and then returns the value parameter that was initially declared in the parent anonymous function

143
Q

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

A

a function’s scope is determined during the definition

144
Q

What allows JavaScript functions to remember values from their surroundings?

A

scope