JavaScript Quiz Questions Flashcards

1
Q

What is a variable?

A

Variables store data

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

Why are variables useful?

A

They are reusable and they can be reassigned later. They are also useful for readability

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

$ and _

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

How do you declare a variable?

A

By using the word var and giving it a name

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

A variable is assigned with a “=”, which is a n 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

Keywords such as “var”, “function”, “true”, etc..

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

What is a string?

A

Data stored in ‘ ‘ or “ “

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

What is the string concatenation operator?

A

The addition operator/ +

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

There is no difference

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

How do you escape quotation characters?

A

With a backward slash \

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

What is type coercion?

A

When JavaScript converts data types behind the scenes to complete an operation

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 data type (primitive data type)

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

What is an arithmetic operator?

A

An operator that performs basic 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

+, -, *, /, –, ++, %

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

What is the order of execution?

A

Multiplication and division are performed before addition or subtraction. Parentheses overpowers everything.

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

What is a boolean?

A

A data type that only returns the values 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

Compares two values and returns true or false

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

The difference is when you declare a variable without giving it any value, the data type of that variable is undefined. Null on the other hand must be assigned programmatically. It represents the absence of value and usually a variable that is null, will have a value later on in the program.

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

Why is null an object?

A

It’s a bug

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

How do you think building this layout would be different without a grid system?

A

It would be a lot of elements with different sizings

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

What advantages do you see with using a grid system?

A

Helps size things quickly, readability, and for mobile responsiveness

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

Why are media queries crucial to responsive grid designs?

A

It helps with mobile responsiveness/ resizing for smaller or bigger screens

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

What is a function?

A

A reusable block of code with a series of statements grouped together to perform a specific task.

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

Why are functions useful?

A

It saves time from writing repetitive code

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

How do you call a function?

A

By writing the function name with the parentheses

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

What are the parts of a function definition?

A

The function keyword, the function name, the parentheses with the parameters, and the function code block

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

What is the difference between a parameter and an argument?

A

Parameter is the name of the variable. Argument is the value of the variable being passed into the function

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

Why is it important to understand truthy and falsy values?

A

To understand possible type coercion errors

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

Why do you want to avoid using == for comparison?

A

Type coercion can lead to errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
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
32
Q

What is the proper syntax for using the or operator?

A

if ( var1 < var2 || var1 > var2)

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

What is the primary use case for switches?

A

For direct 1 to 1 comparisons

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

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

A

No

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

What happens if there is no break statement between cases?

A

The next case will be executed even if the evaluation does not match the case

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

What is an object in JavaScript?

A

An object is a container for a group of properties and values

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

How do you create an object literal?

A

var objectName = {}

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

What is a property in relation to JavaScript objects?

A

A property in relation to objects is a key value pair

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

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

A

When substituting a property or if there are spaces/special characters in a property name

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

How do you remove a property from an object?

A

Use the delete function:

delete objName.propertyName

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

What is an array in JavaScript?

A

A list of data with order/indexs

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

How do you create an array literal?

A

var arrayName = []

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

What are the keys for the values inside an array?

A

Index numbers and values

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

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

A

Objects literals

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

What are some good use cases for using objects inside arrays?

A

Organization and more data

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

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

A

queryselector targets a css selector where as the getElementById only grabs elements Id’s

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

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

A

To reuse that element rather than searching for it on the dom over and over again

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

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

A

In order to update a document more efficiently and as new situations arise, we can alter that document rather than create a brand new one

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

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

A

Create ids and classes

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

What are the differences between innertext and textContent?

A

innerText get the computed text and textContent gets the entire text

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

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

A

‘string’

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

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

A

You would have a static website with text that doesn’t change

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

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

A

It’s better to separate html from javascript

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

Why is the Window.event property useful for finding an element which was interacted with?

A

its helpful because it has a reference to which ever element that event occurred on within the object

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

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

A

Its not dependable for being the same object that you want for the event that you’re dealing with

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

What potential use cases are there for for loops?

A

For counting down

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

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

A

They are all optional, but you should still use all of the information (Initialization, condition, and update)

58
Q

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

A

They are all optional, but you should still use all of the information (Initialization, condition, and final expression)

59
Q

What is a for in loop?

A

A loop that iterates through objects and it properties

60
Q

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

A

bracket notation within the for in loop

61
Q

When should you use a for in loop?

A

When you want to display the data inside an object

62
Q

What kind of information is useful to store in custom attributes?

A

Semantic info

63
Q

What is the difference between the parentNode and parentElement properties?

A

The only difference is that the html element has a parent node of document, but does not have a parent element.

64
Q

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

A

When you are unable to create a class for an element (Very rare situatuion)

65
Q

What are two ways to target elements on the DOM?

A

queryselector and getElement

66
Q

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

A

createTextNode and then appendChild to the element

67
Q

How do you create a HTML element using vanilla Javascript?

A

createElement method

68
Q

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

A

To not have to repeat the code over and over. It cuts time down.

69
Q

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

A

An array is indexed which makes it easier to loop over

70
Q

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

A

It is important to handle user input data

71
Q

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

A

You can’t control what people input and can cause problems with your page

72
Q

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

A

You can’t control what users input and can cause problems with your page, such as hacking.

73
Q

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

A

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

Change the 100 to 500

74
Q

What are the disadvantages of inline styling via JavaScript?

A

Inline script cannot be tested independently of its page; external Javascript files can be run through independent testing, including automated tests

75
Q

What things do you have to consider when building a reset game function?

A

The initial starting values of everything at the beginning of the game

76
Q

What is event bubbling?

A

When event listener is called from the element that was triggered and it moves back up through its parents through to the dom

77
Q

What is the difference between event.target and event.currentTarget.

A

Event target is the element that was initially triggered and currentTarget is the element that has the event listener on it

78
Q

What is the first argument the function setTimeout takes?

A

function

79
Q

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

A

0

80
Q

What are some scenarios where setTimeout can be useful?

A

For a modal that might pop up to ask if you’re still there

81
Q

What does the setInterval function return?

A

It returns a number

82
Q

What argument does the clearInterval function take?

A

The setInterval ID

83
Q

What are some scenarios where setInterval can be useful?

A

Timers

84
Q

What is the event loop?

A

It is responsible for looking at the task queue and pushing events into it from the call stack

85
Q

What does the term blocking mean?

A

When the call stack is full and other events can’t be pushed into it

86
Q

What is the call stack?

A

The current workflow of tasks flowing through Javascript

87
Q

Which elements in a website are useful to create dynamically?

A

Ex: Products on an retail website

88
Q

Why should you not create all elements dynamically?

A

Some elements should be static in html

89
Q

Why do we need a single source of truth?

A

To keep track of where to store data

90
Q

Why would I create a function to generate my DOM Element instead of just writing my code in the global scope?

A

It’s more reusable and versatile

91
Q

What is a method?

A

It’s an object function

92
Q

What does a method do?

A

Retrieve or update the values of an object’s properties

93
Q

What is this?

A

A keyword that grabs a property’s value of an object

94
Q

What does bind do?

A

It binds a permanent argument to a new copied function

95
Q

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

A

functions are callable objects, but they have three methods (apply, bind, call)

96
Q

What is Prototypal Inheritance?

A

Inheritance of methods from the proto object

97
Q

What is the Prototypal Chain?

A

A chain that tries to find a method and if it can’t find the method, it will go all the way up through other objects until it gets to the global object to find a method. It will stop once the method is found.

98
Q

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

A

From the global Object

99
Q

Why does JavaScript have Prototypal Inheritance?

A

Efficiency in memory

100
Q

What does the new keyword do?

A

It creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function

Also

Creates a blank, plain JavaScript object;

Links (sets the constructor of) this object to another object;

Passes the newly created object from Step 1 as the this context;

Returns this if the function doesn’t return an object.

101
Q

I could’ve added a method to the constructor function by assigning a method to a property on the this object. Why do we have to add it to the prototype property?

A

It’s bad for memory efficiency

102
Q

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

A

An empty object is created

103
Q

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

A

Classes will always use the new keyword where as functions can use new, but not always

104
Q

What is a static method?

A

Methods that can be used without creating an instance. It is also attached to the creator/ prototype

105
Q

What is the benefit of instantiating Classes within other classes?

A

So that classes can hold other classes

106
Q

Why are parent - child relationships important in OOP?

A

To create connections

107
Q

What is the basic idea of OOP?

A

Organizations and keeping related things together

108
Q

Why did you have to bind this for the feedChild method in the Parent class?

A

If we didn’t bind it, the “this” would have tried to find the “this.food” within class Child instead of looking for it in the class Parent

109
Q

Why is it important to assign callback methods to properties in the constructor?

A

So that it is defined and can be called later

110
Q

Why did the Maker class require all of the Parent class info?

A

So that it could pass in data into a nested class

111
Q

Why did you have to bind this for the replenishFood method?

A

To look for data in maker

112
Q

What decides the order in which JS files must be loaded?

A

The data being accessed needs to exist before you can access it

113
Q

What is JSON?

A

A text-based data format following JavaScript object syntax

114
Q

What are serialization and deserialization and why are they useful?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.

Deserialization is the reverse process: turning a stream of bytes into an object in memory.

115
Q

How to you serialize data into a JSON string using JavaScript?

A

stringify method

116
Q

How do you deserialize a JSON string using JavaScript?

A

parse method

117
Q

Variables defined with the var keyword are function scoped. const and let are _____ scoped.

A

block

118
Q

Name some characteristics of a variable declared using let.

A

mutable, block-scope, not hoisted

119
Q

What does block scope mean?

A

The scope within the current block of code

120
Q

In the file we can push a new value to an array defined using the const variable. How does that work?

A

We are not changing the value of the variable, just the value within the array

121
Q

Name some things that var can do that const and let can’t.

A

var can be hoisted, var becomes a property of the window obj, var can be reassigned

122
Q

If var can be used virtually anywhere, why would we switch?

A

const and let leave less room for error. Var can do things in your code that you don’t want it too

123
Q

Name some characteristics of a variable declared using const.

A

immutable, block-scope, not hoisted

124
Q

What is the syntax in writing a template literal?

A

${javascript expression}

125
Q

What is string interpolation?

A

A way to inject javascript into a string without concatenation

126
Q

When was destructuring introduced?

A

In 2015 with es6

127
Q

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

A

It can be easy to lose track of the count of commas

128
Q

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

A

The placement of the object literal (left or right)

129
Q

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

A

arguments, super, this, and new.target are lexical in arrow functions and arrow functions can’t be constructors.

130
Q

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

A

Nothing

131
Q

In what situations would you possibly use an arrow function?

A

When lexical scope is needed

132
Q

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

A

When you don’t want to use lexical this

133
Q

What is Array filter useful for?

A

creates a new array of filtered items

134
Q

What is Array map useful for?

A

creates a new array of items that have their values changed or mapped

135
Q

What is Array reduce useful for?

A

executes a function that takes an array and condenses it down into a single value. Kind of liking folding a piece of paper down to a tiny square

136
Q

What is the JavaScript Event Loop?

A

The event loop is a check if the call stack is blocked, if not, it moves the next task in the task queue onto the call stack

137
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

Blocking is synchronous and non blocking is asynchronous.

138
Q

What is JSON?

A

JavaScript Object Notation - common data interchange format used to send and store information in computer systems

139
Q

What are serialization and deserialization?

A

Serialization is the changing of an object in memory into a string of bytes. Deserialization is the opposite

140
Q

Why are serialization and deserialization useful?

A

Many languages use JSON, so it is important so that data from one language can be read by another language. It’s also useful for storing data

141
Q

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

A

the JSON stringify method

142
Q

How do you deserialize a JSON string using JavaScript?

A

the JSON parse method