JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store 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

you the keyword var 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

=

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, underscore, $

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

upper case letters and lower case letters are different

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 a list 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

they are 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

to return the value true or false

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

its an assignment operator

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 put the variable name and = then the 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 means the variable has no value and undefined refers to a value that is empty or doesn’t exist

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 show what is being used

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

Give five examples of JavaScript primitives.

A

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

When two or more strings are joined together to create one new string

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

It adds numbers together or 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 (<, >, ===, etc)?

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

Adds the value on the right to the variable on the left and then assigns that to the left variable

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

What are objects used for?

A

Grouping together a set of variables and functions to create a model of something you would recognize from the real world.

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

What are object properties?

A

A variable within 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 the variable and name it then use curly brace and make property and 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 object.property

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

Storing multiple pieces of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
Create an array and give it a name and then assign values inside of a bracket
26
How are arrays different from "plain" objects?
arrays are used for lists and arrays are used for the same data type
27
What number represents the first index of an array?
0
28
What is the length property of an array?
arrayname.length
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
A set of statements that perform a task
31
Describe the parts of a function definition.
Function keyword, parameters in parentheses, statement enclose in curly braces
32
Describe the parts of a function call.
function keyword and argument in parentheses
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call calls the function while the function definition determines what the function does
34
What is the difference between a parameter and an argument?
a parameter is used in a function definition, while an argument is used on a function call.
35
Why are function parameters useful?
It determines what is to be used as an argument for the function
36
What two effects does a return statement have on the behavior of a function?
it stops the function and returns whatever is after the return keyword
37
Why do we log things to the console?
So we can see what the output of something would be.
38
What is a method?
A method is a function which is a property of an object
39
How is a method different from any other function?
A method is an object property that has a function value, meanwhile a function is a block of code designed to perform a particular task.
40
How do you remove the last element from an array?
you use the .pop() method
41
How do you round a number down to the nearest integer?
you use the Math.floor method
42
How do you generate a random number?
you use the Math.random method
43
How do you delete an element from an array?
you use the .splice(start, deleteCount) method
44
How do you append an element to an array?
you use .push(element) method
45
How do you break a string up into an array?
you use the .split(separator, limit) method
46
Do string methods change the original string? How would you check if you weren't sure?
No they are made into a new string. You can check using console.log method
47
Is the return value of a function or method useful in every situation?
No
48
Give 6 examples of comparison operators.
>, <, >=, <=, ===, !==
49
What data type do comparison expressions evaluate to?
boolean
50
What is the purpose of an if statement?
it allows us to make decision on our code.
51
Is else required in order to use an if statement?
no
52
Describe the syntax (structure) of an if statement.
if (condtion) { conditional code block}
53
What are the three logical operators?
AND(&&), OR (||), NOT(!)
54
How do you compare two different expressions in the same condition?
using &&, ||
55
What is the purpose of a loop?
It allows you to repeat a process until a specific condition is met
56
What is the purpose of a condition expression in a loop?
the purpose is to stop a loop
57
What does "iteration" mean in the context of loops?
a repetition of the loop
58
When does the condition expression of a while loop get evaluated?
before the code block is executed
59
When does the initialization expression of a for loop get evaluated?
it gets evaluated first in the condition and it happens only once
60
When does the condition expression of a for loop get evaluated?
before each iteration
61
When does the final expression of a for loop get evaluated?
after each iteration
62
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break
63
What does the ++ increment operator do?
adds by 1
64
How do you iterate through the keys of an object?
you use the for in loop
65
What is JSON?
a standard text-based format for representing structured data based on JavaScript object syntax.
66
What is serialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.
67
What is deserialization
Deserialization is the reverse process: turning a stream of bytes into an object in memory.
68
Why are serialization and deserialization useful?
so you can turn your data into something that is more easily stored
69
How do you serialize a data structure into a JSON string using JavaScript?
JSON.Stringify
70
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.Parse
71
How do you store data in localStorage?
setItem
72
How do you retrieve data from localStorage?
getItem
73
What data type can localStorage save in the browser?
String
74
When does the 'beforeunload' event fire on the window object?
right when the window is going to close or be reloaded
75
What is a method?
A method is a function which is a property of an object.
76
How can you tell the difference between a method definition and a method call?
method definition includes parameters and it is inside of an object
77
Describe method definition syntax (structure).
its stored in an object and then the function name colon, then function keyword and parameters and function definition
78
Describe method call syntax (structure).
object then dot method name and argument
79
How is a method different from any other function?
Because it is stored in an object
80
What is the defining characteristic of Object-Oriented Programming?
Objects contain both data and behavior
81
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
82
What is "abstraction"?
being able to work complex things in simple ways
83
What does API stand for?
Application programming interface
84
What is the purpose of an API?
Application programming interfaces, or APIs, simplify software development and innovation by enabling applications to exchange data and functionality easily and securely.
85
What is this in JavaScript?
It's a keyword that refers to an object that is executing the current piece of code
86
What does it mean to say that this is an "implicit parameter"?
that it's available in a functions code block even though it was never initialized
87
When is the value of this determined in a function; call time or definition time?
call time
87
How can you tell what the value of this will be for a particular function or method definition?
You can't
88
How can you tell what the value of this is for a particular function or method call?
It's the object of the left of the dot
89
What kind of inheritance does the JavaScript programming language use?
prototypal
90
What is a prototype in JavaScript?
an object with shared behavior or data that can be stored in one place but can be shared in all places
91
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?
If the string, array ,or number had a prototype
92
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
Each prototype object
93
What does the new operator do?
The new operator 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.
94
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
95
What does the instanceof operator do?
It's used to test whether the object is an instance of the specified type
96
What is AJAX?
A programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.
97
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
98
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHTTPRequest
99
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
Load event
100
What is Array.prototype.filter useful for?
it's useful for filtering