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

keyword(var, let, const) with a space followed by the variable number.

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

Using 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

start with $ _ or letters, and can have numbers and letters in it.

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

javascript reads capitals as a differnet letters.

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 text data.

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

To store numbers for use in 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

As a ‘on, off’ switch.

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

It assigns the 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

using a the variable name and assignment operator.

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

undefined means the variable has not been assigned a variable. Null is purposefully left unassigned.

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 things organized and to know what and why your logging something.

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

Give five examples of JavaScript primitives.

A

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

Combining strings togethers.

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

Add two values to another.

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

A boolean value.

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

It adds or concatenates two numbers or strings and then assigns to 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

Used to group together sets of variables and function(methods).

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

What are object properties?

A

They are variables describing the variable they are in.

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

Describe object literal notation.

A

variable assign with {} and key value property pairs.

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

use the delete keyword and the property of the object.

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

using dot or bracket notation and assignment operator.

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

What are arrays used for?

A

Relevant data or lists of data.

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

Describe array literal notation.

A

var array = []

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 properties are the 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

The index starts at 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

the .length property shows the number of items.

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

item.length -1 will give the last index since index starts at 0.

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

What is a function in JavaScript?

A

Is a special object that can be called to run a block of code.

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, optional name and optional paramaters and the code block.

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 name and optional arguments in ().

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 uses parameters instead of arguments, and does not have the function definition and no 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

parameter is an empty variable or placeholder and arguments are values passed through.

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

Why are function parameters useful?

A

They allow use to create lines of code to run with the parameters, arguments when you call 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 produces a usable value and exits the function.

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

We log to the console to see if our output is what we expected.

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

The method must be called in relation to a object, (arrays and strings are objects?)

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

this.pop() removes the last items from an array AND returns it, so it may be assigned to a variable.

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

your use the floor() method of the Math object. Math.floor() and pass the number as an argument.

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

How do you delete an element from an array?

A

You can use the array.splice() method, with arguments in order.
(start index, number to delete, items to replace, items to replace..), also
array.shift, and array.pop

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

How do you append an element to an array?

A

You can use array.push to put an item at the end of an array or array.unshift to place it at the beginning.

44
Q

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

A

They only change a string locally and return the value leaving the original string variable the same.

45
Q

Roughly how many string methods are there according to the MDN Web docs?

A

about 50.

46
Q

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

A

Not always sometimes you don’t need the returned value.

47
Q

Roughly how many array methods are there according to the MDN Web docs?

A

40 - 50

48
Q

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

A

MDN

49
Q

How do you generate a random number?

A

Math.Random

50
Q

How do you break a string up into an array?

A

string.split

51
Q

Give 6 examples of comparison operators.

A

<, >, <=, >=, ===, !==, &&, ||

52
Q

What data type do comparison expressions evaluate to?

A

Booleans

53
Q

What is the purpose of an if statement?

A

To run code if a condition is met.

54
Q

Is else required in order to use an if statement?

A

The else is not required, but is good for formatting.

55
Q

Describe the syntax (structure) of an if statement.

A

if (condition) {code block}

56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

With && and ||.

58
Q

What is the purpose of a loop?

A

to run a code block a certain amount of times under a condition.

59
Q

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

A

Tells us when to stop the loops.

60
Q

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

A

Every time a code block is run a new time.

61
Q

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

A

at the beginning of each iteration.

62
Q

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

A

At the beginning of each iteration.

63
Q

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

A

after the intialization.

64
Q

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

A

after the code block is run.

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

66
Q

What does the ++ increment operator do?

A

It increases a variable by 1

67
Q

How do you iterate through the keys of an object?

A

With a for…in loops.

68
Q

What is JSON?

A

data storage in string format for easy transfer and storage of data models

69
Q

What are serialization and deserialization?

A

serialization is turning objects or array into jsons string format; and desrialization is the reverse, taking the string format and converting it into a javascript object or array

70
Q

Why are serialization and deserialization useful?

A

data can be sent and stored outside of javascript.

71
Q

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

A

JSON.stringify()

72
Q

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

A

JSON.parse()

73
Q

How do you store data in localStorage?

A

Using the method setItem of the localStorage object and pass through prefferably your JSON data.

74
Q

How do you retrieve data from localStorage?

A

Using the method getItems() of the localStorage object.

75
Q

What data type can localStorage save in the browser?

A

A key value pair. of strings

76
Q

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

A

before the page closes.

77
Q

What is a method?

A

method is a function of an object.

78
Q

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

A

object.method() to call
definitions
object.method : function () {}

79
Q

Describe method definition syntax (structure).

A

a property of an object, with colon and then function keyword and normal building of an anonymous function.

80
Q

Describe method call syntax (structure).

A

object.method()

81
Q

How is a method different from any other function?

A

It is called with an object.

82
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data as properties and functions as methods

83
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

84
Q

What is “abstraction”?

A

A simple way of interacting with something. Without understanding the complicated way it happens.

85
Q

What does API stand for?

A

Application programming interface

86
Q

What is the purpose of an API?

A

Allows us to interface with a database in a simple manner.

87
Q

What is this in JavaScript?

A

this is a reference of an object, if no object then the window.

88
Q

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

A

a parameter that is available to use even though it has not been defined. A reference of an object

89
Q

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

A

this value is determined at call time.

90
Q

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);
}
};

A

this refers to the window till its called.

91
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

It’s me mario, because this of greet will reference character.

92
Q

Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();

A

the result of this will be undefined.

93
Q

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

A

You cannot.

94
Q

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

A

look to the left of the ‘.’ or else it is default window.

95
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal Inheritance

96
Q

What is a prototype in JavaScript?

A

The ancestor of data.

97
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 special objects?

98
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 its prototype tree.

99
Q

What does the new operator do?

A

1.Creates a Blank Object.
2. references the constructor as a prototype.
3.runs the constructor function.
4.An extra step to see if something other than an object was created.

100
Q

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

A

Their prototype.

101
Q

What does the instanceof operator do?

A

Checks if a constructor function matches an object.

102
Q

What is a “callback” function?

A

A function that is called as an arguement.

103
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() method.

104
Q

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

A

using setInterval() method

105
Q

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

A

0, run immediately.

106
Q

What do setTimeout() and setInterval() return?

A

an ID number for their timer