JavaScript Quiz Questions Flashcards

1
Q

What is a variable?

A

A container for storing data

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

Why are variables useful?

A

You can reuse them, assign value to them, use for dynamic operations

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

A $sign or _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

The ‘var’ keyword

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

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

other keywords in JS

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

What is a string?

A

A series of characters stored within a pair of “” 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

+ sign

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 you can use apostrophes in “ “ double quotes.

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 backslash

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

What is type coercion?

A

The process of converting one data type value to another

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

What is a number in JavaScript?

A

a primitive datatype

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

What is an arithmetic operator?

A

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

+, -, *, /, %

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

What is the order of execution?

A

PEMDAS

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

What is a boolean?

A

A datatype with the values of 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 a true or false value

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 a variable that has been declared but no value has been assigned.
Null must be assigned and is an empty value.

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

What advantages do you see with using a grid system?

A

Eliminates a lot of repetition, can be saved for later use,

More organized, and segmented.

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

Why are media queries crucial to responsive grid designs?

A

Allows for the page to be viewed on various device sizes so that nothing is cut out or removed due to sizing changes.

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

What is a function?

A

A list of actions to be performed

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

Why are functions useful?

A

Can be reused for multiple purposes, so they save a lot of time

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

How do you call a function?

A

name of the function with () parenthesis

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

What are the parts of a function definition?

A
function keyword,
function definition (name)
(parameters)
{code}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the difference between a parameter and an argument?

A

Parameters are declared when the function is created

Arguments are the data you pass into the function

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

Why is it important to understand truthy and falsy values?

A

Can be important when using them in conditional statements or in comparisons, in case type coercion is used.

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

Why is the typeof null an object?

A

it is a bug

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

What is the difference between null and undefined?

A

Undefined is a declared variable that has not been assigned a value.
Null is an assigned empty value.
Undefined is a type, null is an object

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

Why do you always use === for comparisons?

A

because of type coercion, you might get an inaccurate result

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

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

A

because of type coercion, you might get an inaccurate result

32
Q

Do all if statements require an else statement?

A

No

33
Q

What is the proper syntax for using the or operator?

A

if (num1 < num2 || num1 > num2)

34
Q

What is the primary use case for switches?

A

For comparing multiple 1 on 1 values

35
Q

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

A

No, default can be anywhere on the list

36
Q

What happens if there is no break statement between cases?

A

The switch will continue until the next break statement

37
Q

What is an object in JavaScript?

A

datatype that can hold a group of other data/functions

38
Q

What is a property in relation to JavaScript objects?

A

It is the key/value data within an object

39
Q

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

A

If you have a regular property name that has characters not valid as a property name.
Or substitution of variable names.

40
Q

How do you remove a property from an object?

A

delete object.property

41
Q

What is an array in JavaScript?

A

An object that holds a series of data in a list like structure

42
Q

How do you create an array literal?

A

var array = [ ];

43
Q

What are the keys for the values inside an array?

A

index numbers starting from 0

44
Q

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

A

objects

45
Q

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

A

A list of people (with their information)

-List of cars

46
Q

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

A

So you don’t have to rewrite a lot of code such as “document.getElementById()”.
You can store it into a variable instead.

47
Q

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

A

Dynamic changes to the page according to user input

48
Q

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

A

Use ID’s and classes

49
Q

What are the differences between innertext and textContent?

A

textContent grabs everything, even values that are not visible.
innerText only grabs visible text

textContent is much faster

50
Q

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

A

string

51
Q

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

A

For usability: to allow users to make changes on the website based on their input

52
Q

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

A

Might make the HTML less clear, by adding javascript, instead of keeping them separate
Maybe same reason inline styling is bad, using the function for multiple parts of the code

53
Q

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

A

getElementById() is more specific and quicker.

querySelector() is more broad, general use, and newer, but slightly slower

54
Q

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

A

The javascript engine passes it

55
Q

Does a callback function require a name?

A

No, you can use an anonymous function

56
Q

What is the purpose of a loop?

A

Repeat a set of code for a given number of time

57
Q

Why might there be different kinds of loops?

A

for loops are for incrementing variable.

while loops are for other cases

58
Q

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

A

Lets the loop know when to end, or how long to continue

59
Q

Could a loop potentially go on forever?

A

Yes, if the condition is never false

60
Q

Could a loop never start?

A

Yes, if the condition is already false before the loops begins

61
Q

How does a for loop differ from a while loop?

A

while loops only have a condition in the declaration;

for loops have the incrementation and variable declaration in the

62
Q

What potential use cases are there for for loops?

A

incrementing, you know how long the loop will go on for

63
Q

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

A

for (Initialization; Condition; Final Expression)

64
Q

What is a for in loop?

A

A variation of a for loop designed for objects.

iterates through each property of the object

65
Q

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

A

use bracket notation

ex) object[property]

66
Q

What is the difference between the parentNode and parentElement properties?

A

All elements are nodes, but not all nodes are elements

parentElement ignores whitespace characters

67
Q

What are two ways to target elements on the DOM?

A

querySelector()

getElementById()

68
Q

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

A

createTextNode(text)

69
Q

How do you create a HTML element using vanilla Javascript?

A

createElement() method

70
Q

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

A

Much more efficient, less code to write

71
Q

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

A

arrays have a length property

72
Q

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

A

Handling user input

73
Q

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

A

Users can make typos, or enter incorrect information, or HACKERS

74
Q

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

A

.

75
Q

What are the disadvantages of inline styling via JavaScript?

A

.

76
Q

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

A

.