JavaScript Quiz Questions Flashcards
What is a variable?
Variables store data
Why are variables useful?
They are reusable and they can be reassigned later. They are also useful for readability
What two special characters can a variable begin with?
$ and _
How do you declare a variable?
By using the word var and giving it a name
How do you assign a value to a variable?
A variable is assigned with a “=”, which is a n assignment operator
Are variables case sensitive?
Yes
Which words cannot be used as variable names?
Keywords such as “var”, “function”, “true”, etc..
What is a string?
Data stored in ‘ ‘ or “ “
What is the string concatenation operator?
The addition operator/ +
What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?
There is no difference
How do you escape quotation characters?
With a backward slash \
What is type coercion?
When JavaScript converts data types behind the scenes to complete an operation
What is a number in JavaScript?
Numeric data type (primitive data type)
What is an arithmetic operator?
An operator that performs basic math
Name four of the arithmetic operators
+, -, *, /, –, ++, %
What is the order of execution?
Multiplication and division are performed before addition or subtraction. Parentheses overpowers everything.
What is a boolean?
A data type that only returns the values true or false
What is a comparison operator?
Compares two values and returns true or false
What is the difference between undefined and null?
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.
Why is null an object?
It’s a bug
How do you think building this layout would be different without a grid system?
It would be a lot of elements with different sizings
What advantages do you see with using a grid system?
Helps size things quickly, readability, and for mobile responsiveness
Why are media queries crucial to responsive grid designs?
It helps with mobile responsiveness/ resizing for smaller or bigger screens
What is a function?
A reusable block of code with a series of statements grouped together to perform a specific task.
Why are functions useful?
It saves time from writing repetitive code
How do you call a function?
By writing the function name with the parentheses
What are the parts of a function definition?
The function keyword, the function name, the parentheses with the parameters, and the function code block
What is the difference between a parameter and an argument?
Parameter is the name of the variable. Argument is the value of the variable being passed into the function
Why is it important to understand truthy and falsy values?
To understand possible type coercion errors
Why do you want to avoid using == for comparison?
Type coercion can lead to errors
Do all if statements require an else statement?
No
What is the proper syntax for using the or operator?
if ( var1 < var2 || var1 > var2)
What is the primary use case for switches?
For direct 1 to 1 comparisons
Does the default case have to be at the bottom of the switch statement?
No
What happens if there is no break statement between cases?
The next case will be executed even if the evaluation does not match the case
What is an object in JavaScript?
An object is a container for a group of properties and values
How do you create an object literal?
var objectName = {}
What is a property in relation to JavaScript objects?
A property in relation to objects is a key value pair
When should you use bracket notation over dot notation with objects?
When substituting a property or if there are spaces/special characters in a property name
How do you remove a property from an object?
Use the delete function:
delete objName.propertyName
What is an array in JavaScript?
A list of data with order/indexs
How do you create an array literal?
var arrayName = []
What are the keys for the values inside an array?
Index numbers and values
Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?
Objects literals
What are some good use cases for using objects inside arrays?
Organization and more data
What is the difference between the getElementById() method and the querySelector() method?
queryselector targets a css selector where as the getElementById only grabs elements Id’s
What is the primary advantage to storing your selected elements in a variable?
To reuse that element rather than searching for it on the dom over and over again
Why might you need JavaScript to modify the DOM after the page loads?
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 can you better prepare when writing HTML for DOM manipulation in your JavaScript code?
Create ids and classes
What are the differences between innertext and textContent?
innerText get the computed text and textContent gets the entire text
What datatype are the values you remove from a text input?
‘string’
Why is it so important to be able to dynamically update text?
You would have a static website with text that doesn’t change
What are some of the drawbacks of HTML Event Handler Attributes?
It’s better to separate html from javascript
Why is the Window.event property useful for finding an element which was interacted with?
its helpful because it has a reference to which ever element that event occurred on within the object
Why is the Window.event property to be avoided in new code?
Its not dependable for being the same object that you want for the event that you’re dealing with
What potential use cases are there for for loops?
For counting down