JS Flashcards

1
Q

Why are variables useful?

A

Save data and return to it

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

What two special characters can a variable begin with?

A

$ _

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

How do you declare a variable?

A

var

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

How do you assign a value to a variable?

A

the assignment operator (=)

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

Are variables case sensitive?

A

yes

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

Which words cannot be used as variable names?

A

keywords, cant start with numbers

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

What is a string?

A

data type of text

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

What is the string concatenation operator?

A

+

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

What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?

A

nothing

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

How do you escape quotation characters?

A

/”

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

What is type coercion?

A

a different data type becoming a string only because it was concatenated with a string

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

What is a number in JavaScript?

A

a number

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

What is an arithmetic operator?

A

+, -, *, etc.

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

Name four of the arithmetic operators?

A

+, -, *,/

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

What is the order of execution?

A

PEMDAS

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

What is a boolean?

A

a data type of true and false values

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

What is a comparison operator?

A

an operator that compares variables and returns a boolean value accordingly

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

What is the difference between undefined and null?

A

undefined is an empty variable argument while null is an argument with a specified value of emptiness. A human must specify a null value.

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

What is a function?

A

Functions group statements together to perform a task.

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

Why are functions useful?

A

Functions enable the reuse of these specific groupings of statements in the future as opposed to recreating matching code for different arguments.

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

How do you call a function?

A

functionName(arguments)

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

What are the parts of a function definition?

A
function Name(parameters) {
return code  block
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the difference between a parameter and an argument?

A

a parameter is the required information needed in order to call a function while an argument are the actual values being passed to the function upon its calling

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

Does the default case have to be at the bottom of the switch statement?

A

Nope, but should be

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

What is an object in JavaScript?

A

its a reference data type that contains properties and methods

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

How do you create an object literal?

A

var name = {};

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

When should you use bracket notation over dot notation with objects?

A

when you only want to target properties and not methods

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

How do you remove a property from an object?

A

delete object

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

What is an array in JavaScript?

A

objects are storage area, arrays are for lists to loop through usually

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

How do you create an array literal?

A

var name = []

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

What are the keys for the values inside an array?

A

indexed from 0

32
Q

Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?

A

objects

33
Q

Why is the Window.event property to be avoided in new code?

A

It changes too often so you cannot be certain you’re speaking to the correct event

34
Q

What is the difference between the getElementById() method and the querySelector() method?

A

getElementById()

35
Q

Who passes in the event object into the handleClick callback function?

A

JavaScript

36
Q

Does a callback function require a name?

A

No, but you should

37
Q

What is the purpose of a loop?

A

Repeat functionality that differs slightly in input

38
Q

Why might there be different kinds of loops?

A

Whether you know the exact number of iterations for the loop or not determines between a for and while loop, respectively.

39
Q

What is the purpose of a conditional expression as it relates to loops?

A

Whether or not to continue iterating

40
Q

Could a loop potentially go on forever?

A

Yes

41
Q

Could a loop never start?

A

Yes

42
Q

How does a for loop differ from a while loop?

A

for loop you know the length to loop over

43
Q

Which pieces of information provided in the parentheses for a for loop are mandatory?

A

technically none

44
Q

What potential use cases are there for for loops?

A

anything array

45
Q

What is a for in loop?

A

a loop over the properties of an object

46
Q

How do you target the value of a property in an object.

A

brackets[]

47
Q

When should you use a for in loop?

A

when you want to loop over an object

48
Q

What is the difference between the parentNode and parentElement properties?

A

parentElement is always an element

49
Q

Why is it important to be able to traverse the DOM?

A

Select what element youre selecting based on the elements around it instead of re-searching through the entire DOM.

50
Q

How would you alter the game to make the choice from 1 - 500?

A

Math.floor(Math.random() *500)+1

51
Q

What are the disadvantages of inline styling via JavaScript?

A

Inline styling is very strong and hard to override. Also bad to mix languages?

52
Q

Why is it dangerous to assume you have the correct data when creating elements?

A

You might not have the create elements!

53
Q

What is the first argument the function setTimeout takes?

A

A function definition

54
Q

If the second argument is not passed into the setTimeout function, what is the default value?

A

0ms

55
Q

What are some scenarios where setTimeout can be useful?

A

is the user still there?

56
Q

What does the setInterval function return?

A

the ID

57
Q

What argument does the clearInterval function take?

A

the ID to clear that set interval

58
Q

What are some scenarios where setInterval can be useful?

A

a stopwatch, a timed carousel

59
Q

What is the event loop?

A

it watches the task cue and call stack to shift elements between the two

60
Q

Why do we need a single source of truth?

A

Make sure there are no inconsistencies between DOM and data model

61
Q

What is a method?

A

A function in an object. Object.method()

62
Q

What does a method do?

A

Anything a function can do

63
Q

What is Prototypal Inheritance?

A

When elements inherit properties from other elements in JS

64
Q

What is the Prototypal Chain?

A

When an element cannot find

65
Q

In the custom objects we created, I noticed that our prototype object has another __proto__ property, where did that come from?

A

anytime an object is created with curly braces, the __proto__ is inherited.

66
Q

Why does JavaScript have Prototypal Inheritance?

A

so we can save memory by reusing properties

67
Q

Why are parent - child relationships important in OOP?

A

saving classes onto classes allows them to communicate

68
Q

What is the basic idea of OOP?

A

Avoid spaghetti code.

Super scalable

69
Q

When was destructuring introduced?

A

es6 (es2015)

70
Q

Why could the running commas technique of destructuring an array be a bad idea?

A

Leaves reliance on user correctly counting commas. More room for error.

71
Q

How can you easily tell the difference between destructuring and creating array/object literals.

A

Destructuring places the brackets or braces on the left of the assignment operator while assigning is on the right.

72
Q

How does an ES6 arrow function differ from an ES5 function?

A
() => {} Syntax as opposed to 
function name() {}
73
Q

When an arrow function’s code block is left without curly braces, what (if anything) changes in its functionality?

A

implicit return

74
Q

In what situations would you possibly use an arrow function?

A

Trim syntax, useful when you want to

75
Q

In what situations would you not want to use an arrow function?

A

Constructors, methods