JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to hold values

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

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

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

casing matters

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

for storing and manipulating 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

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

assign

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

the variable name = 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 have a value while undefined does not

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 keep track of what you are logging

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

number

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

What is string concatenation?

A

combining 2 strings into one +=

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

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 does the += “plus-equals” operator do?

A

addition -> assignment

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

What are objects used for?

A

to store data in an unordered list type structure

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

What are object properties?

A

variables, but for objects

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

Describe object literal notation.

A

var newObject = { };

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 operator

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

To store data of the same type together in the same place

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

Describe array literal notation.

A

[]

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

they have a numbered index

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

how long the array is in numbers

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

length of the array - 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 performs 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 -> name (parameters) { code -> optional return }

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

nameOfFunction(arguments);

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

a function call doesn’t include a code block

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 a placeholder which will eventually become an argument with 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

Allows functions to perform tasks without knowing the inputs ahead of time.

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

Causes the function to produce a value we can use in our program. And prevents any more code in the function’s code block from being run.

37
Q

Give 6 examples of comparison operators.

A

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

38
Q

What data type do comparison expressions evaluate to?

A

boolean

39
Q

What is the purpose of an if statement?

A

to check for certain conditions or to force certain parameters

40
Q

Describe the syntax (structure) of an if statement.

A

if (parameters) { return: what you want code to do; }

41
Q

What are the three logical operators?

A

& || !==

42
Q

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

A

& ||

43
Q

What is a method?

A

An object reference to a function

44
Q

How is a method different from any other function?

A

object.

45
Q

How do you remove the last element from an array?

A

.pop()

46
Q

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

A

Math.floor()

47
Q

How do you generate a random number?

A

Math.random()

48
Q

How do you delete an element from an array?

A

.splice(start index, how many, optional replace)

49
Q

How do you append an element to an array?

A

.push()

50
Q

How do you break a string up into an array?

A

.split()

51
Q

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

A

No, and with console.log()

52
Q

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

A

No

53
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

54
Q

What is JSON?

A

JavaScript Object Notation, used for storing and transporting data

55
Q

What are serialization and deserialization?

A

Serialization converts an object into a byte stream and Deserialization does the opposite.

56
Q

Why are serialization and deserialization useful?

A

Serialization allows you to save an object in a file or database. Deserialization takes that saved object and recreates it somewhere else.

57
Q

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

A

JSON.stringify()

58
Q

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

A

JSON.parse()

59
Q

How do you store data in localStorage?

A

window.localStorage.setItem()

60
Q

How do you retrieve data from localStorage?

A

window.local.Storage.getItem()

61
Q

What data type can localStorage save in the browser?

A

string

62
Q

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

A

before the page is refreshed or left

63
Q

What is a method?

A

A function that is a property of an object.

64
Q

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

A

A method definition has a return statement

65
Q

Describe method definition syntax (structure).

A

the object’s property (name for function) followed by function (anything) { random code; optional return;}

66
Q

Describe method call syntax (structure).

A

The name of the object followed by it’s property in dot notation followed by it’s arguments. console.log(‘Doggo’, doggo);

67
Q

How is a method different from any other function?

A

A method is associated with an object

68
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain both data (as properties) and behavior (as methods)

69
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

70
Q

What is “abstraction”?

A

The process of generalizing details

71
Q

What does API stand for?

A

Application Programming Interface

72
Q

What is the purpose of an API?

A

To allow for two or more computers to communicate with each other.

73
Q

What is this in JavaScript?

A

An implicit parameter of all JavaScript functions

74
Q

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

A

It’s baseline

75
Q

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

A

call time

76
Q

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

A

You can’t

77
Q

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

A

Object to the left of the period

78
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal

79
Q

What is a prototype in JavaScript?

A

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

80
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

They are objects?

81
Q

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

A

In it’s prototype

82
Q

What does the new operator do?

A
  • Creates a new object
  • It sets this new object’s internal, inaccessible, [[prototype]] (i.e. __proto__) property to be the constructor function’s external, accessible, prototype object (every function object automatically has a prototype property).
  • It makes the this variable point to the newly created object.
  • If no return statement, object gets returned
83
Q

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

A

prototype

84
Q

What does the instanceof operator do?

A

It tests whether the object is an instance of the specified type

85
Q

What is a “callback” function?

A

Passing a function as an argument

86
Q

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?

A

setTimeout()

87
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

88
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0

89
Q

What do setTimeout() and setInterval() return?

A

Interval id