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
Describe array literal notation
square brackets
26
How are arrays different from plain objects?
ordered, use index
27
What number represents the first index of an array?
0
28
What is the length property of an array?
can be called to find the length of the array
29
How do you calculate the last index of an array?
array.length-1
30
What two effects does a return statement have on the behavior of a function?
returns a value and exits code block
31
Why are function parameters useful?
allows functions to run with certain values
32
What is the difference between a parameter and an argument?
parameter is for defining, argument for calling
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition has function keyword and {}
34
Describe the parts of a function call.
function call consists of function name and parentheses and possible arguments
35
Describe the parts of a function definition.
function keyword, function name, parentheses, possible parameters, {}
36
What is a function in JavaScript?
code that can be repeated over and over again easily
37
Why do we log things to the console?
so that we can see that things are being input correctly
38
What is a method?
a function that is a property of an object
39
How is a method different from any other function?
functions themselves are objects, so a method is actually an object reference to a function
40
How do you remove the last element from an array?
pop method
41
How do you round a number down to the nearest integer?
floor method
42
How do you generate a random number?
random method
43
How do you delete an element from an array?
splice method
44
How do you append an element to an array?
push or unshift (prepend) method
45
How do you break a string up into an array?
split method
46
Do string methods change the original string? How would you check if you weren't sure?
mdn, console log, they do not
47
Roughly how many string methods are there according to the MDN Web docs?
a lot
48
Roughly how many array methods are there according to the MDN Web docs?
a lot
49
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
50
Give 6 examples of comparison operators
there is the equal to, less than, greater than, strictly equal to, less than or equal to, and greater than or equal to
51
What data type do comparison expressions evaluate to?
boolean
52
What is the purpose of an if statement?
to make a decision
53
Is else required in order to use an if statement?
no
54
Describe the syntax of an if statement
if statement, () with conditionals inside, {} with rule to run if conditions are met
55
What are the three logical operators?
logical and, logical or, logical not
56
How do you compare two different expressions in the same condition?
use logical and or logical or
57
When does the condition expression of a while loop get evaluated?
after the initialization, and at the beginning of every loop
58
What does "iteration" mean in the context of loops?
you loop and then add something to count up
59
What is the purpose of a condition expression in a loop?
to see if you continue looping
60
What is the purpose of a loop?
to perform actions over and over again
61
How do you iterate through the keys of an object?
for in loops
62
What does the ++ increment operator do?
increment by 1
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
When does the final expression of a for loop get evaluated?
just before the condition is met
65
When does the initialization expression of a for loop get evaluated?
beginning of the loop
66
What is the event.target?
the object of the element that the event had happened to
67
What is the affect of setting an element to display: none?
removes from document flow
68
What does the element.matches() method take as an argument and what does it return?
takes in a string and returns a boolean
69
How can you retrieve the value of an element's attribute?
getAttribute()
70
At what steps of the solution would it be helpful to log things to the console?
when you assign variables
71
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?
you would have to include many more event listeners
72
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?
you would have to include many more if statements
73
What is JSON?
json is a string whose format resembles an object literal format
74
What are serialization and deserialization?
serialization is making objects into strings and deserialization is the reverse
75
Why are serialization and deserialization useful?
converting to json and back
76
How do you serialize a data structure into a JSON string using JavaScript?
stringify
77
How do you deserialize a JSON string into a data structure using JavaScript?
parse
78
How do you store data in localStorage?
you can store data in localStorage by storage.setItem() method
79
How do you retrieve data from localStorage?
use storage.getItem() method
80
What data type can localStorage save in the browser?
JSON strings
81
When does the 'beforeunload' event fire on the window object?
when the window, the document, and its resources are about to be unloaded
82
What is a method?
a method is a function which is a property of an object
83
How can you tell the difference between a method definition and a method call?
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
Describe method definition syntax (structure).
``` var object = { method: function (parameter) { do something; } } ```
85
Describe method call syntax (structure).
object.method(argument);
86
How is a method different from any other function?
it is a property of an object
87
What is the defining characteristic of Object-Oriented Programming?
it is based on the concept of objects which contain data and code
88
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation, inheritance, and polymorphism
89
What is "abstraction"?
abstraction is modeling and simplifies things for us
90
What does API stand for?
application programming interface
91
What is the purpose of an API?
gives programmers a way to interact with a system in a simplified, consistent fashion
92
What is this in JavaScript?
this is an implicit parameter that uses the object that it is attached to
93
What does it mean to say that this is an implicit parameter?
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
When is the value of this determined in a function; call time or definition time?
call time
95
``` 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); } }; ```
the object character
96
Given the above character object, what is the result of the following code snippet? Why? character.greet();
message will be logged to the console with string: | 'It's-a-me, Mario!'
97
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
you are essentially calling this.firstName on something that does not have a first name property so it returns undefined
98
How can you tell what the value of this will be for a particular function or method definition?
cannot be sure
99
How can you tell what the value of this is for a particular function or method call?
left of the dot
100
What kind of inheritance does the JavaScript programming language use?
prototype-based inheritance
101
What is a prototype in JavaScript?
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
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?
use prototype objects to assign those things to them
103
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
in the object __proto__
104
What does the new operator do?
creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function
105
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
106
What does the instanceof operator do?
it tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
107
What is a "callback" function?
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
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?
use the setTimeout() function
109
How can you set up a function to be called repeatedly without using a loop?
use setInterval() function
110
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
111
What do setTimeout() and setInterval() return?
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
What is a code block? What are some examples of a code block?
``` 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
What does block scope mean?
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
What is the scope of a variable declared with const or let?
they are block scoped
115
What is the difference between let and const?
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
Why is it possible to .push() a new value into a const variable that points to an array?
only the reference cannot be changed but the value that is being point at can be changed
117
How should you decide on which type of declaration to use?
are you going to be reassigning variables? use let. if not then use const
118
What is the syntax for writing a template literal?
instead of using single quotes or double quotes, a template literal uses backticks
119
What is "string interpolation"?
the ability to substitute part of the string for the values of variables or expressions which is also called string formatting
120
What is destructuring, conceptually?
Breaking down into individual pieces
121
What is the syntax for object destructuring?
var { property, property: variableNameYouWant } = obj
122
What is the syntax for array destructuring?
const [ firstIndexToCopy, secondIndexToCopy, , fourthIndexToCopy ] = arr
123
How can you tell the difference between destructuring and creating Object/Array literals?
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
What is the syntax for defining an arrow function?
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
When an arrow function's body is left without curly braces, what changes in its functionality?
does not return anything
126
How is the value of this determined within an arrow function?
at definition time
127
What are the three states a Promise can be in?
pending, fulfilled, rejected
128
How do you handle the fulfillment of a Promise?
use a then statement
129
How do you handle the rejection of a Promise?
use the optional argument of a then statement or a catch statement
130
What is Array.prototype.filter useful for?
it is selective for the elements in your array
131
What is Array.prototype.map useful for?
Making adjustments to all the elements in your array
132
What is "syntactic sugar"?
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
What is the typeof an ES6 class?
it is a function
134
Describe ES6 class syntax.
``` class className { constructor (name) { this.name = name } ``` getName() { return this.name; } }
135
What is "refactoring"?
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
How are ES Modules different from CommonJS modules?
different syntax, static, has direct support for asynchronous loading and configurable module loading
137
What kind of modules can Webpack support?
ecmascript, commonjs, amd, assets, webassembly
138
What does fetch() return?
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
What is the default request method used by fetch()?
get
140
How do you specify the request method (GET, POST, etc.) when calling fetch?
in the optional arguments
141
What must the return value of myFunction be if the following expression is possible? myFunction()();
it returns a function
142
``` What does this code do? const wrap = value => () => value; ```
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
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
a function's scope is determined during the definition
144
What allows JavaScript functions to remember values from their surroundings?
scope