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
Q

Describe array literal notation.

A

Create an array and give it a name and then assign values inside of a bracket

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

How are arrays different from “plain” objects?

A

arrays are used for lists and arrays are used for the same data type

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

arrayname.length

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

How do you calculate the last index of an array?

A

array.length - 1

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

What is a function in JavaScript?

A

A set of statements that perform a task

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

Describe the parts of a function definition.

A

Function keyword, parameters in parentheses, statement enclose in curly braces

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

Describe the parts of a function call.

A

function keyword and argument in parentheses

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

Function call calls the function while the function definition determines what the function does

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

What is the difference between a parameter and an argument?

A

a parameter is used in a function definition, while an argument is used on a function call.

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

Why are function parameters useful?

A

It determines what is to be used as an argument for the function

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

What two effects does a return statement have on the behavior of a function?

A

it stops the function and returns whatever is after the return keyword

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

Why do we log things to the console?

A

So we can see what the output of something would be.

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

What is a method?

A

A method is a function which is a property of an object

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

How is a method different from any other function?

A

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.

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

How do you remove the last element from an array?

A

you use the .pop() method

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

How do you round a number down to the nearest integer?

A

you use the Math.floor method

42
Q

How do you generate a random number?

A

you use the Math.random method

43
Q

How do you delete an element from an array?

A

you use the .splice(start, deleteCount) method

44
Q

How do you append an element to an array?

A

you use .push(element) method

45
Q

How do you break a string up into an array?

A

you use the .split(separator, limit) method

46
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

No they are made into a new string. You can check using console.log method

47
Q

Is the return value of a function or method useful in every situation?

A

No

48
Q

Give 6 examples of comparison operators.

A

> , <, >=, <=, ===, !==

49
Q

What data type do comparison expressions evaluate to?

A

boolean

50
Q

What is the purpose of an if statement?

A

it allows us to make decision on our code.

51
Q

Is else required in order to use an if statement?

A

no

52
Q

Describe the syntax (structure) of an if statement.

A

if (condtion) { conditional code block}

53
Q

What are the three logical operators?

A

AND(&&), OR (||), NOT(!)

54
Q

How do you compare two different expressions in the same condition?

A

using &&, ||

55
Q

What is the purpose of a loop?

A

It allows you to repeat a process until a specific condition is met

56
Q

What is the purpose of a condition expression in a loop?

A

the purpose is to stop a loop

57
Q

What does “iteration” mean in the context of loops?

A

a repetition of the loop

58
Q

When does the condition expression of a while loop get evaluated?

A

before the code block is executed

59
Q

When does the initialization expression of a for loop get evaluated?

A

it gets evaluated first in the condition and it happens only once

60
Q

When does the condition expression of a for loop get evaluated?

A

before each iteration

61
Q

When does the final expression of a for loop get evaluated?

A

after each iteration

62
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

Break

63
Q

What does the ++ increment operator do?

A

adds by 1

64
Q

How do you iterate through the keys of an object?

A

you use the for in loop

65
Q

What is JSON?

A

a standard text-based format for representing structured data based on JavaScript object syntax.

66
Q

What is serialization?

A

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
Q

What is deserialization

A

Deserialization is the reverse process: turning a stream of bytes into an object in memory.

68
Q

Why are serialization and deserialization useful?

A

so you can turn your data into something that is more easily stored

69
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.Stringify

70
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.Parse

71
Q

How do you store data in localStorage?

A

setItem

72
Q

How do you retrieve data from localStorage?

A

getItem

73
Q

What data type can localStorage save in the browser?

A

String

74
Q

When does the ‘beforeunload’ event fire on the window object?

A

right when the window is going to close or be reloaded

75
Q

What is a method?

A

A method is a function which is a property of an object.

76
Q

How can you tell the difference between a method definition and a method call?

A

method definition includes parameters and it is inside of an object

77
Q

Describe method definition syntax (structure).

A

its stored in an object and then the function name colon, then function keyword and parameters and function definition

78
Q

Describe method call syntax (structure).

A

object then dot method name and argument

79
Q

How is a method different from any other function?

A

Because it is stored in an object

80
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects contain both data and behavior

81
Q

What are the four “principles” of Object-Oriented Programming?

A

abstraction, encapsulation, inheritance, polymorphism

82
Q

What is “abstraction”?

A

being able to work complex things in simple ways

83
Q

What does API stand for?

A

Application programming interface

84
Q

What is the purpose of an API?

A

Application programming interfaces, or APIs, simplify software development and innovation by enabling applications to exchange data and functionality easily and securely.

85
Q

What is this in JavaScript?

A

It’s a keyword that refers to an object that is executing the current piece of code

86
Q

What does it mean to say that this is an “implicit parameter”?

A

that it’s available in a functions code block even though it was never initialized

87
Q

When is the value of this determined in a function; call time or definition time?

A

call time

87
Q

How can you tell what the value of this will be for a particular function or method definition?

A

You can’t

88
Q

How can you tell what the value of this is for a particular function or method call?

A

It’s the object of the left of the dot

89
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal

90
Q

What is a prototype in JavaScript?

A

an object with shared behavior or data that can be stored in one place but can be shared in all places

91
Q

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?

A

If the string, array ,or number had a prototype

92
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

Each prototype object

93
Q

What does the new operator do?

A

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
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

prototype property

95
Q

What does the instanceof operator do?

A

It’s used to test whether the object is an instance of the specified type

96
Q

What is AJAX?

A

A programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.

97
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

98
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHTTPRequest

99
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

Load event

100
Q

What is Array.prototype.filter useful for?

A

it’s useful for filtering