JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to hold data that can used or referenced later

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 the keywords var, const, and let and then the variable name

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

use the assignment operator =

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, $, _ , and numbers but numbers cannot be the first character

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

var number and var Number are 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 and manipulate text

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

math, quantities, count things

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

true or false values, booleans exist for decision making. this or that

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. giving value to 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

refer to the variable again and give it 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

both carry empty values, but null is intentionally assigned - it’s organic. undefined is inorganic. it comes from JavaScript. Baked into the language.

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

it will give us a point of reference

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, and 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 two or more string values

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

adds numbers and concatenates strings

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>, <a>></a>, ===, etc)?</a>

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

take current value and addon whatever we stated and the result of that expression if the new value of the variable.

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

What are objects used for?

A

area to store data under one hood so everything is easier to access

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

What are object properties?

A

variables of the object

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

Describe object literal notation.

A

{
key: value,
key: value
}

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 keyword

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

to store values with order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
``` var example = [ 'thing1', thing2, thing3 ]; ```
26
How are arrays different from "plain" objects?
arrays have order, indexes are not individually named, will repair themselves if an index is deleted, have a set length
27
What number represents the first index of an array?
0
28
What is the length property of an array?
stores the total amount of stuff in the array
29
How do you calculate the last index of an array?
subtract by 1 from the length property
30
What is a function in JavaScript?
a set of statements to perform a task that can help you repeat a certain task
31
Describe the parts of a function definition.
``` function name-of-function(parameter) { ___; return ____; } ```
32
Describe the parts of a function call.
name of function, (), and arguments if need be
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call - actual values are being passed in function definition - curly braces, a code block, function keyword
34
What is the difference between a parameter and an argument?
parameter - placeholder value | argument - the actual value
35
Why are function parameters useful?
without parameters, functions would always do the exact same thing, as in give the exact same result every time and the function can't apply for other instances. ADAPTABILITY
36
What two effects does a return statement have on the behavior of a function?
returns a result and ends the function
37
Why do we log things to the console?
so we know if there are any errors in our code at any given time
38
What is a method?
function that's a property of an object
39
How is a method different from any other function?
methods have to say where they're coming from
40
How do you remove the last element from an 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?
shift(), pop(), splice()
44
How do you append an element to an array?
push()
45
How do you break a string up into an array?
split()
46
Do string methods change the original string? How would you check if you weren't sure?
no. console log it or MDN
47
Roughly how many string methods are there according to the MDN Web docs?
A lot
48
Is the return value of a function or method useful in every situation?
no
49
Roughly how many array methods are there according to the MDN Web docs?
a lot
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
51
Give 6 examples of comparison operators.
===, <, >, <=, >=, !==
52
What data type do comparison expressions evaluate to?
booleans
53
What is the purpose of an if statement?
you're checking a certain condition and if it passes the criteria, do something
54
Is else required in order to use an if statement?
no
55
Describe the syntax (structure) of an if statement.
if (condition) { code here }
56
What are the three logical operators?
||, &&, !
57
How do you compare two different expressions in the same condition?
use the logical operators
58
What is the purpose of a loop?
to do something over and over again until a certain point
59
What is the purpose of a condition expression in a loop?
use the condition to continue a task or stop
60
What does "iteration" mean in the context of loops?
passing through the code block
61
When does the condition expression of a while loop get evaluated?
beginning and before each iteration
62
When does the initialization expression of a for loop get evaluated?
beginning. happens only once
63
When does the condition expression of a for loop get evaluated?
before each iteration
64
When does the final expression of a for loop get evaluated?
at the end of 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
66
What does the ++ increment operator do?
increments the variable by one
67
How do you iterate through the keys of an object?
for in loop
68
What event is fired when a user places their cursor in a form control?
focus
69
What event is fired when a user's cursor leaves a form control?
blur
70
What event is fired as a user changes the value of a form control?
input
71
What event is fired when a user clicks the "submit" button within a ?
submit
72
What does the event.preventDefault() method do?
Prevents the browser from automatically reloading with the forms values in the URL/prevents default behavior of the form
73
What does submitting a form without event.preventDefault() do?
Automatically load the form values.
74
What property of a form element object contains all of the form's controls.
elements property
75
What property of form a control object gets and sets its value?
value
76
What is one risk of writing a lot of code without checking to see if it works so far?
code could be broken and you have no idea where it broke
77
What is an advantage of having your console open when writing a JavaScript program?
know immediately when your program runs into an error
78
What is JSON?
JavaScript Object Notation. data exchange format that contains a string
79
What are serialization and deserialization?
serial - convert object into string so it can be transferrable deserial - convert bytes into stream of data
80
Why are serialization and deserialization useful?
you can send objects over a network and it can be parsed by the receiver. serialization makes it easier + more efficient to send data deserialization is reading that data
81
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify
82
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
83
How to you store data in localStorage?
setItem
84
How to you retrieve data from localStorage?
getItem
85
What data type can localStorage save in the browser?
strings
86
When does the 'beforeunload' event fire on the window object?
before the page/tab closes/unloads
87
How can you tell the difference between a method definition and a method call?
a method definition has a code block. a method call is just the method name and ()
88
Describe method definition syntax (structure).
methodName (parameter) {}
89
Describe method call syntax (structure).
methodName()
90
How is a method different from any other function?
method is a property of an object. still a function though
91
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
92
What are the four "principles" of Object-Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
93
What is "abstraction"?
being able to work with (possibly) complex things in simple ways
94
What does API stand for?
It is a type of software interface, offering a service to other pieces of software
95
What is the purpose of an API?
give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction
96
What is this in JavaScript?
this is an implicit parameter of all JavaScript functions
97
What does it mean to say that this is an "implicit parameter"?
Its available in a function code block even though it was never included in the functions parameter
98
When is the value of this determined in a function; call time or definition time?
call time
99
``` 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); } }; ```
nothing. this is determined at call time not definition
100
Given the above character object, what is the result of the following code snippet? Why? character.greet();
It's a me, Mario
101
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
it's a me, undefined it's just the anon function that is being assigned to hello. the anon function is being "detached" from the character object. hello is attached to the window. window does not have a firstName property thus giving you undefined.
102
How can you tell what the value of this will be for a particular function or method definition?
You can't
103
How can you tell what the value of this is for a particular function or method call?
left of the dot . | if there's no dot, then window by default
104
What kind of inheritance does the JavaScript programming language use?
prototypal inhertiance
105
What is a prototype in JavaScript?
object that contains properties and (predominantly) methods that can be used by other objects
106
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?
__proto__ object
107
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
its placed in a prototype object and then the objects will delegate to that object when they aren’t able to perform the required tasks themselves.
108
What does the new operator do?
lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
109
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
110
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.
111
What is a "callback" function?
a function that's being passed around like a value
112
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()
113
How can you set up a function to be called repeatedly without using a loop?
setInterval()
114
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 - immediately
115
What do setTimeout() and setInterval() return?
interval id which is an integer