JavaScript Flashcards

1
Q

What is the purpose of variables?

A

a vehicle to have permanence of data

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

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

=

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, number $ and _

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

uppercase =/= lowercase

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

for math

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

for conditionals, to make decisions

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

value is being assigned to

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

reassign 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 is an assigned value without value, undefined has never been 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

for context in the output

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

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

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

What is string concatenation?

A

joining 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 JavaScript?

A

concatenation or addition

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 are objects used for?

A

To store multiple variables under one name

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

What are object properties?

A

individual piece of named data within an object

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

Describe object literal notation.

A

var object = {} with commas after each new variable

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

How do you remove a property from an object?

A

with the delete operator

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

What are the two ways to get or update the value of a property?

A

dot or square bracket notation

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

What is a function in JavaScript?

A

A repeatable set of actions with a specific name

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

Describe the parts of a function definition

A

Function keyword with the name of the function followed by () with optional parameters inside, curly braces with code inside and a return statement to give back a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe the parts of a function call
Function name, (), with optional arguments inside the parentheses
26
When comparing them side by side, what are the differences between a function call and a function definition
A function call has just the name with the arguments inside the following parentheses. Whereas the definition has the word function followed by the functions name and parameters inside the parenthesis with a following code block containing a return
27
What is the difference between a parameter and an argument?
parameter is in the function definition. argument is the real data being passed to the function
28
Why are function parameters useful?
it allows you to have variance in the application of the function
29
Why do we log things to the console?
debugging, verification
30
What is a method?
A function in an object
31
How is a method different from any other function?
Function inside an object rather than by itself. function() vs obj.method()
32
How do you remove the last element from an array?
pop() method
33
How do you round a number down to the nearest integer?
Math.floor()
34
How do you generate a random number?
Math.random()
35
How do you delete an element from an array?
splice()
36
How do you append an element to an array?
push()
37
How do you break a string up into an array?
split()
38
Do string methods change the original string? How would you check if you weren't sure?
no, console log to check
39
Give 6 examples of comparison operators.
==, !=, ===, >, <, >=
40
What data type do comparison expressions evaluate to?
boolean
41
What is the purpose of an if statement?
allows us to take decisions in our code
42
Is else required in order to use an if statement?
no
43
What are the three logical operators?
&&, ||, !
44
How do you compare two different expressions in the same condition?
and, or
45
What is the purpose of a loop?
To be able to do things repeatedly
46
What is the purpose of a condition expression in a loop?
To create a point in which the loop will stop
47
What does "iteration" mean in the context of loops?
Each time the loop runs
48
When does the condition expression of a while loop get evaluated?
before each run
48
When does the initialization expression of a for loop get evaluated?
only once before it runs
49
When does the condition expression of a for loop get evaluated?
before each iteration
50
When does the final expression of a for loop get evaluated?
after each run
51
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
52
What does the ++ increment operator do?
increases val of variable by 1
53
How do you iterate through the keys of an object?
for in loop
54
What are the four components of "the Cascade".
Source order, specificity, !important, and inheritance
55
What does the term "source order" mean with respect to CSS?
the order that css rules are written in the stylesheet
56
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?
inheritance
57
List the three selector types in order of increasing specificity.
type, class, ID
58
Why is using !important considered bad practice?
Its high specificity makes it hard to overwrite
59
What event is fired when a user places their cursor in a form control?
focus
60
What event is fired when a user's cursor leaves a form control?
blur
61
What event is fired as a user changes the value of a form control?
input
62
What event is fired when a user clicks the "submit" button within a
?
submit
63
What does the event.preventDefault() method do?
prevents the event from being submitted blank
64
What does submitting a form without event.preventDefault() do?
refreshes page with data in url
65
What property of a form element object contains all of the form's controls.
elements
66
What property of a form control object gets and sets its value?
value
67
What is one risk of writing a lot of code without checking to see if it works so far?
you could be writing many bugs
68
What is an advantage of having your console open when writing a JavaScript program?
you can see a log after every line of code you write
69
What is JSON?
text-based data interchange format based on javascript object syntax
70
What are serialization and deserialization?
turning pieces of data into a string of data
71
Why are serialization and deserialization useful?
to be able to send data and make it easy to receive
72
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify method
73
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse method
74
How do you store data in localStorage?
setItem(key, value)
75
How do you retrieve data from localStorage?
getItem(key)
76
What data type can localStorage save in the browser?
String
77
When does the 'beforeunload' event fire on the window object?
before closing the tab
78
What is a method?
A function assigned to a property of an object
79
How can you tell the difference between a method definition and a method call?
Definition has a function keyword and a code block in assignment, call has a obj name with ()
80
Describe method definition syntax (structure).
Function name with : then function keyword and paramteters inside () and a code block
81
Describe method call syntax (structure).
object name and dot then method()
82
How is a method different from any other function?
it has dot notation
83
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both data and behavior
84
What are the four "principles" of Object-Oriented Programming?
abstraction, inheritance, encapsulation, polymorphism
85
What is "abstraction"?
simplification for interaction with something complex
86
What does API stand for?
application programming interface
87
What is the purpose of an API?
allows apps to exchange data and functionality
88
What is this in JavaScript?
implicit parameter of all javascript functions, it gives the current object from where the function or method was called
89
What does it mean to say that this is an "implicit parameter"?
parameter that is given to all functions, and not listen in the parameter list
90
When is the value of this determined in a function; call time or definition time?
call time
91
How can you tell what the value of this will be for a particular function or method definition?
You can't unless its called
92
How can you tell what the value of this is for a particular function or method call?
by seeing where it was called from
93
What kind of inheritance does the JavaScript programming language use?
Prototypal inheritance
94
What is a prototype in JavaScript?
an object with shared behavior or data that can be stored in one place and shared by all created instances
95
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?
because they have assigned prototypes with those methods
96
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
through its prototypal chain, one layer at a time
97
What does the new operator do?
Makes a new blank object with preset prototypes
98
What property of JavaScript functions can store shared behavior for instances created with new?
the prototype property
99
What does the instanceof operator do?
Tests if the prototype constructor is anywhere in the chain for the object
100
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()
101
How can you set up a function to be called repeatedly without using a loop?
setInterval()
102
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0ms
103
What do setTimeout() and setInterval() return?
an ID for the specific timer
104
What is AJAX?
building webpages using XMLHttpRequest to dynamically update
105
What does the AJAX acronym stand for?
Async javascript and XML
106
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
107
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
the load event
108
What is the JavaScript Event Loop?
part of the runtime that pushes async requests to the call stack when the call stack is clear
109
What is different between "blocking" and "non-blocking" with respect to how code is executed?
no other code can run until the blocking code completes running