JavaScript Flashcards

1
Q

What is a variable?

A

A way to hold data

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

Why are variables useful?

A

It can hold data that changes

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

What two special characters can a variable begin with?

A

dollar sign and underscore

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

How do you declare a variable?

A

Using the keyword “var”

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

How do you assign a value to a variable?

A

With the assignment operator “=”

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

Are variables case sensitive?

A

Yes

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

Which words cannot be used as variable names?

A

can’t start with a digit, no punctuation or special characters, keywords

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

What is a string?

A

datatype to represent text stored with quotation marks

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

What is the string concatenation operator?

A

+

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

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

A

No difference, but has to start and end with same quote

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

How do you escape quotation characters?

A

Backslash before the quote to let the interpreter know that it is part of the string instead the end of it.

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

What is type coercion?

A

JS will convert that value to the type it needs

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

What is a number in JavaScript?

A

Numeric Values

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

What is an arithmetic operator?

A

Operators can do math

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

Name four of the arithmetic operators?

A

+ (addition), - (subtraction), * (multiplication), / (division) %(remainder, modulus)

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

What is the order of execution?

A

By precedence - mult, div, comes first. Parenthesis overpowers everything.

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

What is a boolean?

A

data type that is true or false

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

What is a comparison operator?

A

> < and it returns a boolean

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

What is the difference between undefined and null?

A

undefined is an absence of a value, null is intentional absence of object value

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

What is a function?

A

group a series of statements together to perform a specific task

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

Why are functions useful?

A

reusable code

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

How do you call a function?

A

function name ( )

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

What are the parts of a function definition?

A

function keyword, function name, parameter, code block

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

What is the difference between a parameter and an argument?

A

declaring a function they are parameters and calling a function they are arguments

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

What is the difference between null and undefined?

A

Null is an object and undefined is undefined

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

Why do you always use === for comparisons?

A

Due to type coercion

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

Do all if statements require an else statement?

A

No

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

What is the proper syntax for using the or operator?

A

|

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

What is the primary use case for switches?

A

Comparing a value to many values

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

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

A

No it can jump back to the default

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

What happens if there is no break statement between cases?

A

It will continually run all cases even if it’s met

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

What is an object in JavaScript?

A

Set of variables and functions / collection of related data

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

How do you create an object literal?

A

curly braces, and its contents

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

What is a property in relation to JavaScript objects?

A

variables

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

How do you remove a property from an object?

A

delete keyword object name and property

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

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

A

variable that you need to substitute

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

What is an array in JavaScript?

A

list or set of values that are related to each other that are ordered.

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

How do you create an array literal?

A

[ ]

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

What are the keys for the values inside an array?

A

index number

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

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

A

objects

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

What is the primary advantage to storing your selected elements in a variable?

A

To be able to use it without selecting the elements again

42
Q

Why might you need JavaScript to modify the DOM after the page loads?

A

better user experience and manipulate data without refreshing the page.

43
Q

How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?

A

class name, ID

44
Q

What are the differences between innertext and textContent?

A

innerText gets only the text and not the elements that are hidden

45
Q

What datatype are the values you remove from a text input?

A

String

46
Q

Why is it so important to be able to dynamically update text?

A

A way to communicate with the user

47
Q

What are some of the drawbacks of HTML Event Handler Attributes?

A

To keep HTML and Javascript separate

48
Q

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

A

Old technique

49
Q

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

A

QuerySelector chooses the first one that matches the argument

50
Q

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

A

JavaScript

51
Q

Does a callback function require a name?

A

You can have anonymous but should always have a name

52
Q

What is the purpose of a loop?

A

Reiterate through elements

53
Q

Why might there be different kinds of loops?

A

While loops are better to have a value you are comparing. For loops are useful when you have a variable you want to increment

54
Q

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

A

To let the loop know when to end or continue the loop

55
Q

Could a loop potentially go on forever?

A

Yes if the expression is never found false.

56
Q

Could a loop never start?

A

Yes. if the expression never results true

57
Q

What potential use cases are there for for loops?

A

iterate through an array.

58
Q

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

A

nothing

59
Q

What is a for in loop?

A

Iterates to property names in objects

60
Q

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

A

bracket notation within that for in loop

61
Q

When should you use a for in loop?

A

To debug

62
Q

What is the difference between the parentNode and parentElement properties?

A

Selects just the note and the other selects the whole element

63
Q

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

A

Be able to target elements directly

64
Q

What are two ways to target elements on the DOM?

A

querySelector and getElementBy

65
Q

What is another way to add a text node to an element other than using textContent.

A

createTextNode and appendChild

66
Q

How do you create a HTML element using vanilla Javascript?

A

createElement()

67
Q

Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?

A

More efficient, instead of writing the same code every single time

68
Q

Why are arrays preferred over objects for the functionality referenced in question 1?

A

Array is index and easy to loop over and keep one collection of data

69
Q

Why is it important to be able to retrieve and use data from inputs?

A

To be able to store data

70
Q

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

A

Because due to user error

71
Q

What is jQuery?

A

File included in webpages that lets one find elements using css-style selectors

72
Q

What is the jQuery selector function?

A

jquery() or $()

73
Q

What does the jQuery selector function return?

A

Object

74
Q

Why would someone use jQuery over vanilla Javascript?

A

selecting elements is simpler because it uses CSS style syntax
cross browser
made a selection and can apply multiple methods to it

75
Q

What are some downsides from using jQuery over vanilla Javascript?

A

library is very large and has to parse

76
Q

Why do we use the tag at the bottom of the body, instead of putting it inside the <head> tag?

A

the way the document parses is from top to bottom

77
Q

Why do we use the tag at the bottom of the body, instead of putting it inside the <head> tag?

A

the way the document parses is from top to bottom

78
Q

How do you get the text out of an HTML element?

A

.text method

79
Q

How do you get the value out of an HTML input field?

A

.val method

80
Q

What’s the difference between .text() and .html()?

A

.text only returns the content from every element in the selection as opposed to .html returns the html inside the first element.

81
Q

What does .on() do?

A

handle events

82
Q

What does .on() do?

A

handle events

83
Q

What is event bubbling?

A

starts the event that triggered the event and goes up to each parent.

84
Q

Target and current target

A

Target - the element that triggered the event

currentTarget - what element was actually attached to the event handler

85
Q

Target and current target

A

Target - the element that triggered the event

currentTarget - what element was actually attached to the event handler

86
Q

What is the first argument the function setTimeout takes?

A

Function

87
Q

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

A

0 so immediately

88
Q

What are some scenarios where setTimeout can be useful?

A

Modal to pop up,

89
Q

What argument does the clearInterval function take?

A

ID that is returned by the set interval function

90
Q

What does the term blocking mean?

A

Delaying the code to execute because the call stack is blocked

91
Q

What is the call stack?

A

data structure - pushes and pops to the stack. arrangement of actions that need to be taken

92
Q

What is the call stack?

A

data structure - pushes and pops to the stack. arrangement of actions that need to be taken

93
Q

What is a modal?

A

overlay a small element over a website

94
Q

What are some use cases for modals?

A

Overlays to advise for activity, information, approval

95
Q

Why does a modal usually need to occupy the entire height and width of the viewport?

A

to not let the user evade it

96
Q

What is this?

A

This is used to return values in the properties of the object

97
Q

What does bind do?

A

method that sets the this keyword to the object passed in

98
Q

What is the difference between a function and an object literal?

A

functions have 3 methods - apply, bind, call but are also objects still.

99
Q

What is the first thing that happens in a class when it is instantiated with the new keyword?

A

Always first makes an empty object

100
Q

Since classes are technically functions as well. Can you name a difference between classes and functions?

A

Use the new keyword

101
Q

What is a static method?

A

attached to the creator