Javascript Flashcards

1
Q

What is the purpose of variables?

A

storing 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

Var 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

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

number, text, $, _ 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

capitalizing letters will affect the variable.

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 add any kind of 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

for tasks relating to counting or calculating

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 store a true or false/ determining which part of a script should run.

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

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

by writing the variable name and assigning it 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
undefined =  (a variable that has been declared, but no value has been assigned to it yet)
null = a variable with no value - it may have had one at some point, but no longer has a value
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

So you or your readers can understand what is displayed.

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, undefined, null

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

What are objects used for?

A

grouping together a set of variables and functions. Used to model things.

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

What are object properties?

A

variables that are part of an object.

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

Describe object literal notation.

A

A way of creating objects by setting variables inside of curly braces.

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

How do you remove a property from an object?

A

use the delete keyword followed by the object name . and property name.

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

What are the two ways to get or update the value of a property?

A

dot notation or square brackets

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

What data type is returned by an arithmetic operation?

A

number type

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

What is string concatenation?

A

Combining two or more strings

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

What purpose(s) does the + plus operator serve in JavaScript?

A

Adds one value to another or concatenating strings

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

What data type is returned by comparing two values (, ===, etc)?

A

Booleans

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

What does the += “plus-equals” operator do?

A

add content to an existing variable.

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

What are arrays used for?

A

Storing 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

var blank = [‘…’, ‘…’, ‘…’]

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 store a list of values instead of just one.

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

determines length of array (how many properties are in it)

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

subtract 1 from the total number of index values.

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

What is a function in JavaScript?

A

Similar to a procedure takes some input and returns output

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

writing the name of the function and placing () parentheses next to it

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

Why do we log things to the console?

A

To check output

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

What is Method?

A

Function which is the property of an object.

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

How is a method different from any other function?

A

Both are objects but a method is a object reference to a function.

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

How do you remove the last element from an array?

A

The pop() Method

37
Q

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

A

The Math.floor() Method

38
Q

How do you generate a random number?

A

Math.random() Method

39
Q

How do you delete an element from an array?

A

The Splice() method to remove an item, shift() Method to remove the first item, or pop()Method to remove last item.

40
Q

How do you append an element to an array?

A

push method.

41
Q

How do you break a string up into an array?

A

The split() Method

42
Q

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

A

No??? Its performing an action, not modifying the string. console log it and check

43
Q

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

A

51

44
Q

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

A

No

45
Q

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

A

33?

46
Q

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

A

MDN??

47
Q

Give 6 examples of comparison operators.

A

Equal to ==, not equal to !=, === strict equal to, !=== strict not equal to, greater than, less than, less than or equal to, greater then or equal to.

48
Q

What data type do comparison expressions evaluate to?

A

boolean (true and false)

49
Q

What is the purpose of an if statement?

A

Evaluates a condition and if true executes the code block.

50
Q

is else required in order to use an if statement?

A

No

51
Q

Describe the syntax (structure) of an if statement.

A

if (condition) and if condition is met run instructions.

52
Q

What are the three logical operators?

A

Logical and &&, Logical or ||, logical not !.

53
Q

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

A

comparison operator such as equal to or less then or greaten then.

54
Q

What is the purpose of a loop?

A

A way to repeat a sequence of instructions until a specific condition is met.

55
Q

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

A

tests each time a loop repeats until the condition is no longer met.

56
Q

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

A

The process or stage of repeating steps.

57
Q

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

A

A while loop evaluates its condition before the first iteration, and in between each subsequent iteration.

58
Q

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

A

The condition is tested at the beginning of each iteration of the loop.

59
Q

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

A

after the initialization expression is evaluated

60
Q

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

A

after both the initialization and condition expression are evaluated.

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

62
Q

What does the ++ increment operator do?

A

increases the value of a variable by 1

63
Q

How do you iterate through the keys of an object?

A

For in loop.

64
Q

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

A

Focus? When the user enters a field

65
Q

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

A

blur? When the user leaves a field

66
Q

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

A

input? When the value of an element changes

67
Q

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

A

submit? Has the same effect as clicking the submit button on a form

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

69
Q

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

A

Runs the default event as normal

70
Q

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

A

formElement property?

71
Q

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

A

value property?

72
Q

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

A

You then have to work through your code and figure out where the issue is

73
Q

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

A

You can see your progress and check for mistakes.

74
Q

What is JSON

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).

75
Q

What are serialization and deserialization?

A

Serialization: is a process of converting an Object into a stream of bytes so that it can be transferred over a network or stored in a persistent storage.

Deserialization: is the exact opposite - Fetch a stream of bytes from network or persistence storage and convert it back to the Object with the same state.

76
Q

Why are serialization and deserialization useful?

A

Allows you to send and store information that other people can use.

77
Q

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

A

JSON.stringify() method

78
Q

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

A

JSON.parse() method

79
Q

What is the event.target?

A

reference to the object that was triggered

80
Q

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

A

Hides your element without deleting it

81
Q

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

A

the argument is a string representing the selector to test and the return is a boolean

82
Q

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

A

getattribute method

83
Q

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

A

Every step

84
Q

If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?

A

individual event listeners

85
Q

If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

A

if else block

86
Q

How to you store data in localStorage?

A

You would use the setItem method

87
Q

How to you retrieve data from localStorage?

A

You would use the getItem method

88
Q

What data type can localStorage save in the browser?

A

JSON strings

89
Q

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

A

when the window, the document and its resources are about to be unloaded.