JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data (temporarily) that can be accessed later

have a value that persists

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 variableName;

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

var variableName = (variable 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 signs, underscore
no dash or period
cannot start with a number

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

score != Score

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

store data with text content

save a series of 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

count, math, measurement

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 make decisions

determine which part of a script should run

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

assignment operator
assigns a value to a variable
updates value given to a variable

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

How do you update (reassign) the value of a variable?

A

using equal sign (assignment operator) to assign it a new value
var is only necessary the first time

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 means no value
undefined means variable has not been declared/given a value
null MUST be 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

to know which value or variable is being logged

helpful for catching bugs

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

Give 5 examples of JavaScript primitives

A

string, number, boolean, undefined, 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

a number (always)

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

What is string concatenation?

A

combination of two or more string values (or number)

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

What purpose(s) does the + operator serve in JavaScript?

A

adds on value to another 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?

A

a boolean true or false

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

What does the += operator do?

A

adds the value of the value on right to the current variable and assigns the result to that variable

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

What are objects used for?

A

storing a set of variables and functions
bringing data together
create a collection of stuff that make sense

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

What are object properties?

A

individual pieces of data 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

The object which contains a set of properties and values inside curly braces being assigned to a variable

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

Use the delete operator followed by the object and property name

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

storing a list or set of values that are related to each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
var nameOfArray = straight brackets filled with items
26
How are arrays different from "plain" objects?
the keys for the values of the array are indexed | to add something to array: push method
27
What number represents the first index of an array?
0
28
What is the length property of an array?
holds the number of items in an array
29
How do you calculate the last index of an array?
nameOfArray.length - 1;
30
What is a function in JavaScript?
a special kind of object that can be called and reused to perform a task
31
Describe the parts of a function defintion
function keyword and name of the function, called with 0 or more parameters, with the code block enclosed in curly braces
32
Describe the parts of a function call
function name with parentheses called with 0 or more params
33
When comparing them side-by-side, what are the diffs between a function call and a function definition?
``` calling a function requires the name of the function with arguments function definition is the function itself that takes parameters ```
34
What is the diff between a parameter and an argument?
argument: passed into function when it's called parameter: tied to the function definition
35
Why are function parameters useful?
to pass additional info into the function and have dynamic data gives us a tool that can be more generalized
36
What two effects does a return statement have on the behavior of a function?
prevents any more code in function's code block to be run | produces values / exits the function
37
Why do we log things to the console?
to test your functions and methods to see if you see what you expect
38
What is a method?
a function which is a property of an object
39
How is a method different from any other function?
a method is associated with an object | while a function is not
40
How do you remove the last element from an array?
pop method | pop method of the array object
41
How do you round a number down to the nearest integer?
floor method of the Math object
42
How do you generate a random number?
Math.random, then multiply that by the range, and call it with the floor method
43
How do you delete an element from an array?
splice method of the array object
44
How do you append an item to an array?
push method of the array object
45
How do you break a string up into an array?
split method of the array object | ' ' gets replaced with individual items in an array
46
Do string methods change the original string? How would you check if you weren’t sure?
no. | you can log values of the strings to the console to check
47
Roughly how many string methods are there according to the MDN Web docs?
a lot because strings are an important date type
48
Is the return value of a function or method useful in every situation?
no | for ex, pop method removes an item, and sometimes we don't need it anymore
49
Roughly how many array methods are there according to the MDN Web docs?
a lot because arrays are important. They change values and stuff
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN | include the language as well
51
Give 6 examples of comparison operators
greater than, less than, greater than or equal to, less than or equal to, strictly equal to, strictly not equal to
52
What data type do comparison expressions evaluate to?
boolean
53
What is the purpose of an if statement?
to execute something if the condition is a truthy
54
Is else required in order to use an if statement?
no
55
Describe the syntax (structure) of an if statement.
if keyword followed by condition inside parentheses, followed by curly braces for the if statement
56
What are the three logical operators?
&&, double pipes ||, and !
57
How do you compare two different expressions in the same condition?
by using logical operators between the expressions inside parentheses
58
What is the purpose of a loop?
to do something repeatedly
59
What is the purpose of a condition expression in a loop?
If the value of the condition expression is true, the loop statements execute If the condition is false, the for loop stops *tells the loop when to run
60
What does “iteration” mean in the context of loops?
The process of executing a loop | *each instance of running the for loop code block
61
When does the condition expression of a while loop get evaluated?
it runs as long as it's true
62
When does the initialization expression of a for loop get evaluated?
It’s the first thing that’s run | *before anything, allows us to set a start
63
When does the condition expression of a for loop get evaluated?
it runs after the initialization and for each iteration as long as the condition is true
64
When does the final expression of a for loop get evaluated?
It runs last | After each iteration
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
'break' keyword
66
What does the ++ increment operator do?
Increments the variable by 1.
67
How do you iterate through the keys of an object?
- for (var key in object)
68
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
First one is a variable, second is a function being called (which isn’t good)
69
What is JSON?
- Text-based data format following JavaScript object syntax - Can be used independently from JavaScript - Exists as a string, useful for transmitting data across a network - Needs to be converted to a native JavaScript object when you want to access the data * string format meant to replicate the format of JavaScript objects
70
What are serialization and deserialization?
- Serialization: process of turning an object in memory into a stream of bytes so you can store it on disk or send it over the network - Deserialization: reverse process, turning a stream of bytes into an object in memory
71
Why are serialization and deserialization useful?
You can transfer objects across networks and deserialize them again later * efficiently
72
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
73
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
74
How do you store data in localStorage?
localStorage.setItem('key', 'value')
75
How do you retrieve data from localStorage?
localStorage.getItem('keyName')
76
What data type can localStorage save in the browser?
strings
77
When does the ‘beforeunload’ event fire on the window object?
when the window, document and its resources are about to be unloaded
78
What is a method?
A function which is a property of an object Two kinds: instance, built-in tasks performed by an object instance / static, tasks that are called directly on an object constructor
79
How can you tell the difference between a method definition and a method call?
A method definition has a function defined with the code block, while a method call is just the property of an object
80
Describe method definition syntax (structure).
Assign an object literal to a variable, and each property key is a method with a value of a function definition
81
Describe method call syntax (structure).
The name of the variable for the object, dot notation, method name, and finally the arguments
82
How is a method different from any other function?
Methods are properties of objects, while functions are not
83
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both data (as properties) and behavior (as methods)
84
What are the four “principles” of Object-Oriented Programming?
Abstraction, encapsulation, inheritance, polymorphism
85
What is “abstraction”?
Being able to work with complex things in simple ways / “generalization”
86
What does API stand for?
Application programming interface
87
What is the purpose of an API?
Allows apps to send information between each other / let one piece of software communicate with another The purpose of every software API is to give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction. * allows users to use a piece of code without having to understand everything about it
88
What is a "callback" function?
A function passed into another function as an argument
89
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?
Calling a number value in milliseconds as an argument in the methods * setTimeout function
90
How can you set up a function to be called repeatedly without using a loop?
setInterval() method
91
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
92
What do setTimeout() and setInterval() return?
A numeric, non-zero value that identifies the timer created by the call to the method (setInterval()) * a number, as a unique ID, to identify the timers created from the functions, not mathematical value