JavaScript Quiz Questions Flashcards
What is a variable?
A container for storing data
Why are variables useful?
You can reuse them, assign value to them, use for dynamic operations
What two special characters can a variable begin with?
A $sign or _underscore
How do you declare a variable?
The ‘var’ keyword
How do you assign a value to a variable?
with the equals sign
Are variables case sensitive?
Yes
Which words cannot be used as variable names?
other keywords in JS
What is a string?
A series of characters stored within a pair of “” marks
What is the string concatenation operator?
+ sign
What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?
No difference, but you can use apostrophes in “ “ double quotes.
How do you escape quotation characters?
With a backslash
What is type coercion?
The process of converting one data type value to another
What is a number in JavaScript?
a primitive datatype
What is an arithmetic operator?
operators that do math
Name four of the arithmetic operators?
+, -, *, /, %
What is the order of execution?
PEMDAS
What is a boolean?
A datatype with the values of true or false
What is a comparison operator?
Compares two values and returns a true or false value
What is the difference between undefined and null?
Undefined is a variable that has been declared but no value has been assigned.
Null must be assigned and is an empty value.
What advantages do you see with using a grid system?
Eliminates a lot of repetition, can be saved for later use,
More organized, and segmented.
Why are media queries crucial to responsive grid designs?
Allows for the page to be viewed on various device sizes so that nothing is cut out or removed due to sizing changes.
What is a function?
A list of actions to be performed
Why are functions useful?
Can be reused for multiple purposes, so they save a lot of time
How do you call a function?
name of the function with () parenthesis
What are the parts of a function definition?
function keyword, function definition (name) (parameters) {code}
What is the difference between a parameter and an argument?
Parameters are declared when the function is created
Arguments are the data you pass into the function
Why is it important to understand truthy and falsy values?
Can be important when using them in conditional statements or in comparisons, in case type coercion is used.
Why is the typeof null an object?
it is a bug
What is the difference between null and undefined?
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
Why do you always use === for comparisons?
because of type coercion, you might get an inaccurate result
Why do you want to avoid using == for comparison?
because of type coercion, you might get an inaccurate result
Do all if statements require an else statement?
No
What is the proper syntax for using the or operator?
if (num1 < num2 || num1 > num2)
What is the primary use case for switches?
For comparing multiple 1 on 1 values
Does the default case have to be at the bottom of the switch statement?
No, default can be anywhere on the list
What happens if there is no break statement between cases?
The switch will continue until the next break statement
What is an object in JavaScript?
datatype that can hold a group of other data/functions
What is a property in relation to JavaScript objects?
It is the key/value data within an object
When should you use bracket notation over dot notation with objects?
If you have a regular property name that has characters not valid as a property name.
Or substitution of variable names.
How do you remove a property from an object?
delete object.property
What is an array in JavaScript?
An object that holds a series of data in a list like structure
How do you create an array literal?
var array = [ ];
What are the keys for the values inside an array?
index numbers starting from 0
Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?
objects
What are some good use cases for using objects inside arrays?
A list of people (with their information)
-List of cars
What is the primary advantage to storing your selected elements in a variable?
So you don’t have to rewrite a lot of code such as “document.getElementById()”.
You can store it into a variable instead.
Why might you need JavaScript to modify the DOM after the page loads?
Dynamic changes to the page according to user input
How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?
Use ID’s and classes
What are the differences between innertext and textContent?
textContent grabs everything, even values that are not visible.
innerText only grabs visible text
textContent is much faster
What datatype are the values you remove from a text input?
string
Why is it so important to be able to dynamically update text?
For usability: to allow users to make changes on the website based on their input
What are some of the drawbacks of HTML Event Handler Attributes?
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
What is the difference between the getElementById() method and the querySelector() method?
getElementById() is more specific and quicker.
querySelector() is more broad, general use, and newer, but slightly slower
Who passes in the event object into the handleClick callback function?
The javascript engine passes it
Does a callback function require a name?
No, you can use an anonymous function
What is the purpose of a loop?
Repeat a set of code for a given number of time
Why might there be different kinds of loops?
for loops are for incrementing variable.
while loops are for other cases
What is the purpose of a conditional expression as it relates to loops?
Lets the loop know when to end, or how long to continue
Could a loop potentially go on forever?
Yes, if the condition is never false
Could a loop never start?
Yes, if the condition is already false before the loops begins
How does a for loop differ from a while loop?
while loops only have a condition in the declaration;
for loops have the incrementation and variable declaration in the
What potential use cases are there for for loops?
incrementing, you know how long the loop will go on for
Which pieces of information provided in the parentheses for a for loop are mandatory?
for (Initialization; Condition; Final Expression)
What is a for in loop?
A variation of a for loop designed for objects.
iterates through each property of the object
How do you target the value of a property in an object.
use bracket notation
ex) object[property]
What is the difference between the parentNode and parentElement properties?
All elements are nodes, but not all nodes are elements
parentElement ignores whitespace characters
What are two ways to target elements on the DOM?
querySelector()
getElementById()
What is another way to add a text node to an element other than using textContent.
createTextNode(text)
How do you create a HTML element using vanilla Javascript?
createElement() method
Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?
Much more efficient, less code to write
Why are arrays preferred over objects for the functionality referenced in question 1?
arrays have a length property
Why is it important to be able to retrieve and use data from inputs?
Handling user input
Why is it dangerous to assume you have the correct data when creating elements?
Users can make typos, or enter incorrect information, or HACKERS
How would you alter the game to make the choice from 1 - 500?
.
What are the disadvantages of inline styling via JavaScript?
.
What things do you have to consider when building a reset game function?
.