javaScript Flashcards

1
Q

What is the purpose of variables?

A

Storing data and going back to use it

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

How do you declare a variable?

A

Using keyword “var”

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

Must begin with a letter, _underscore, or $ dollar-sign

can’t start with 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

Uppercase and lowercases matter

Must be consistent with captializations

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

String data types are in quotes

Used to add new content into a page

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

Used to mathematical tasks

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

Assigning a value to the 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

Assigning different values to the variable

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 - represents a reference point for nonexistent or invalid objects (space for value) (purposeful)
Undefined - how JS tells you nothing (not purposeful) not purposed result of a declared object

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

Describes the description of the value, in order to debug
ex:
var debug = letsgo;
console.log(“so that you can debug:”, debug);

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

Numbers

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

What is string concatenation?

A

It’s adding 2 strings together

Strings are textual content

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

And also concatenation of 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

The Addition-assignment operator adds value 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

To hold its properties and functions in order to create a model

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

What are object properties?

A

Properties are tells us specific characteristics of the object that relate to each other
Properties Variables glued to objects

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

Describe object literal notation.

A

Declares the variable equating to curly braces

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

Using the dot notation to the object

Using square bracket notation with the property inside

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

What are arrays used for?

A

Container for lists

Special type of objects.

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

Describe array literal notation.

A

Square objects

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 hold a related set of key/value, but the key for each value is its numerical indexes (not alpha numeric)
In an array, order of properties are important
-Square brackets instead of curly braces

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 index

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

Holds the number of items in the 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

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

Function keyword, function name, parentheses, curly braces for definition 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 keyword, function name, parentheses to pass 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

function call - function keyword, name of function and arguments, doesn’t have curly braces after

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 empty variables - placeholders (function def)
Arguments are actual values - actual values (function call)

35
Q

Why are function parameters useful?

A

Useful to store and run future data.

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. (return a result)
Prevents any more code in the function’s code block from being run (stops the code)

37
Q

Why do we log things to the console?

A

In order to debug and check your progress

38
Q

What is a method?

A

Function which is a property of an object

Built-in tasks that operate

39
Q

How is a method different from any other function?

A

Can be Property of an object

40
Q

How do you remove the last element from an array?

A

.pop() method

41
Q

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

A

Using Math.floor method (which is a static method using . dot notation)

42
Q

How do you generate a random number?

A

Use Math.random method

43
Q

How do you delete an element from an array?

A

.splice( ) method

44
Q

How do you append an element to an array?

A

.push ( ) method

45
Q

How do you break a string up into an array?

A

split ( ) method

46
Q

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

A

no

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
== is equal to
! = is not equal to
=== strictly equal to
! == strictly not equal to
> greater than
< less than
49
Q

What data type do comparison expressions evaluate to?

A

boolean

50
Q

What is the purpose of an if statement?

A

Declares and evaluates a conditional statement in order to make a decision

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 - keyword
(score > 0 ) - condition expression
{ opening curly brace for statement 1
} curly brace for statement 1

53
Q

What are the three logical operators?

A

&& logical and
| | logical or
! logical not

54
Q

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

A

Place logical operators in between

55
Q

What is the purpose of a loop?

A

To check the conditions until limit of false or the count of the condition

56
Q

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

A

It serves as a counter, stops the loop

57
Q

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

A

It repeats the condition expression

58
Q

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

A

After declaring the counter

59
Q

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

A

At statement 1, before the condition ONCE

60
Q

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

A

final expression and before the code block, before each iteration

61
Q

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

A

Running after the code block

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 1 to the variable

64
Q

How do you iterate through the keys of an object?

A

It takes the object that you want to loop over as an argument and returns an array containing all properties names (or keys)
For-in loops
Navigate over objects

65
Q

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

A

focus

66
Q

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

A

blur

67
Q

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

A

input

68
Q

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

A

Submit (event occurs)

69
Q

What does the event.preventDefault() method do?

A

Default prevents a form (but event still occurs)

70
Q

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

A

If you don’t prevent, the page refreshes

71
Q

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

A

Element’s property (use the elements property to get the elements

72
Q

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

A

The value of property retrieve or give value

73
Q

What is the event.target?

A

The target property of the Event interface is a reference to the object onto which the event was dispatched

74
Q

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

A

it will not display on the viewpage

75
Q

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

A

argument 1 - selectorString is a string representing the selector to test.
argument 2 - result is a boolean value.

76
Q

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

A

getAttribute() method

77
Q

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

A

console.log at every step

78
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

You would have to add event-listener to all

79
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

Use conditional statements

80
Q

How to you store data in localStorage?

A

localStorage.setItem(keyName, keyValue)

81
Q

How to you retrieve data from localStorage?

A

localStorage.getItem

82
Q

What data type can localStorage save in the browser?

A

JSON Strings

83
Q

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

A

beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.