JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Variables are for storing bits of information.

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

How do you declare a variable?

A

Variables are declared using the variable keyword and variable name. For example, var quantity; is a variable declaration.

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

Variables are initialized by 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

Variable names will accept letters, numbers, dollar signs, and underscores. However, variable names cannot start with a number.

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

This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of 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

The purpose of a string is to store and manipulate 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

Numbers are primarily used for arithmetic expressions.

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

A boolean denotes a true or false value which allows a program to analyze and respond to conditions.

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

The = operator is used to assign values to variables.

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 can update the value of a variable by using the assignment operator to store a 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

A null value is assigned intentionally, whereas a value of undefined is typically given by JavaScript.

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

Labels improve readability and aids in debugging when you log values to the browser console.

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, and undefined are five examples of JavaScript primitives.

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

An arithmetic operation returns a data type of number.

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

What is string concatenation?

A

Concatenation is the process of appending one string to the end of another 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

The + plus operator is used to perform addition in JavaScript. You can also concatenate strings by using the + plus operator.

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

Comparing two values will return a data type of 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

The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result 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

Objects group together a set of variables and functions to create a model of a 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 property is 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

The object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last.

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

You can remove a property from an object using the delete keyword.

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

You can use dot and bracket notation to get or update the value of a property.

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

What are arrays used for?

A

An array is used to store a list of values.

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

Describe array literal notation.

A

Array literal notation is where you define a new array using just empty brackets.

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

?

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 first index of an array is represented by the number 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 of an array returns the number of elements in that array.

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

You can calculate the last index of an array by subtracting 1 from the array’s length.

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 JavaScript 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
31
Q

Describe the parts of a function definition.

A

A function definition includes the name of the function. A list of parameters to the function, enclosed in parentheses and separated by commas. It also includes the JavaScript statements that define the function, enclosed in curly brackets,

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

A function call is comprised of the function’s name followed by parentheses. Arguments go inside of the parentheses separated by commas.

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 is the name of the function followed by parentheses which may contain arguments separated by commas. Whereas a function definition is made up of the function keyword, an optional name, and parentheses which may include parameters separated by commas. Function definitions also include JavaScript statements that define the function which are enclosed in curly brackets.

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

Parameters are used in a function’s definition whereas arguments are used when a function is being called or ‘invoked’.

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

Why are function parameters useful?

A

Parameters are useful because a function can utilize those values when it is called.

36
Q

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

A

A return statement ends the execution of a function, and returns control to the calling function

37
Q

What is the purpose of a loop?

A

The purpose of a loop is for repeating code and describing when to stop repeating code.

38
Q

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

A

Condition expressions returns a boolean value that tells the code whether or not to continue running.

39
Q

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

A

Each time the loop runs is called an iteration.

40
Q

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

A

The condition expression of a while loop is analyzed before each iteration.

41
Q

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

A

The initialization expression is the very first step of a for loop.

42
Q

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

A

The condition expression is evaluated before each iteration.

43
Q

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

A

The final expression is evaluated after each iteration.

44
Q

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

A

The break keyword.

45
Q

What does the ++ increment operator do?

A

It moves the value of a variable forward by one.

46
Q

How do you iterate through the keys of an object?

A

Use a for in loop.

47
Q

What event is fired when a user places their cursor in a form control?

A

The mouseover event is fired.

48
Q

What event is fired when a user’s cursor leaves a form control?

A

The mouseout event is fired.

49
Q

What event is fired as a user changes the value of a form control?

A

The input event is fired.

50
Q

What event is fired when a user clicks the “submit” button within a form?

A

The submit event is fired.

51
Q

What does the event.preventDefault() method do?

A

The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur.

52
Q

What does submitting a form without event.preventDefault() do?

A

Submitting a form without event.preventDefault() will cause the form to disappear.

53
Q

What property of a form element object contains all of the form’s controls.

A

The HTMLFormProperty element contains all of the form’s controls.

54
Q

What property of form a control object gets and sets its value?

A

Elements

55
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

You are risking making numerous bugs in your code.

56
Q

What is an advantage of having your console open when writing a JavaScript program?

A

You can log elements and see what is inside of them.

57
Q

What is the event.target?

A

The target property gets the element on which the event originally occurred.

58
Q

What is the affect of setting an element to display: none?

A

The element becomes hidden.

59
Q

What does the element.matches() method take as an argument and what does it return?

A

The method takes a selector string as an argument and returns a boolean.

60
Q

How can you retrieve the value of an element’s attribute?

A

Use the getAttribute() method.

61
Q

At what steps of the solution would it be helpful to log things to the console?

A

Logging to the console is a first step because you should check if your code works.

62
Q

What is JSON?

A

JSON is a format for formatting and transporting data.

63
Q

What are serialization and deserialization?

A

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process.

64
Q

Why are serialization and deserialization useful?

A

Serialization is useful to update information stored on a server. Deserialization is useful for making data readable in JavaScript.

65
Q

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

A

Use the JSON.stringify() method.

66
Q

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

A

Use the JSON.parse() method.

67
Q

How to you store data in localStorage?

A

Use the setItem() method.

68
Q

How to you retrieve data from localStorage?

A

Use the getItem() method.

69
Q

What data type can localStorage save in the browser?

A

String data.

70
Q

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

A

Before the page loads.

71
Q

What is a method?

A

JavaScript methods are actions that can be performed on objects. A JavaScript method is a property containing a function definition.

72
Q

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

A

A method call will be preceded by an object and a dot, followed by parentheses. A method definition is done inside of an object.

73
Q

Describe method definition syntax (structure).

A

Declare an object literal and make a property whose value is a function definition.

74
Q

Describe method call syntax (structure).

A

The method is called with a parentheses. It is preceded by a dot on the left which is preceded by the name of an object.

75
Q

How is a method different from any other function?

A

A function is an object, a method is a function that belongs to an object.

76
Q

What is the defining characteristic of Object-Oriented Programming?

A

The use of models to represent real world things we want to use in our programs.

77
Q

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

A

Encapsulation, abstraction, inheritance, and polymorphism.

78
Q

What is “abstraction”?

A

Only using necessary information to reduce complexity in programming.

79
Q

What does API stand for?

A

Application Programming Interface

80
Q

What is the purpose of an API?

A

It allows applications to interact with one another.

81
Q

What is ‘this’ in JavaScript?

A

‘this’ is an implicit parameter of all JavaScript functions.

82
Q

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

A

It is available in a function’s code block even though it was never included in the function’s parameter list or declared with ‘var’.

83
Q

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

A

Call time.

84
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based inheritance

85
Q

What is a prototype in JavaScript?

A

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

86
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

This is possible because of prototypal inheritance.

87
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 the __proto__ property of the object.