JavaScript Flashcards
What is the purpose of variables?
To store data types to later recall that information.
How do you declare a variable?
With var, let, const.
How do you initialize (assign a value to) a variable?
With an assignment operator (=).
What characters are allowed in variable names?
They can contain letters, numbers, dollar signs, or an underscore, but numbers cannot be the first character.
What does it mean to say that variable names are “case sensitive”?
Variable names are different if they have different letters capitalized or lower cased.
What is the purpose of a string?
Strings can be used when working with any kind of text.
What is the purpose of a number?
To be able to give a variable a numeric data type for math.
What is the purpose of a boolean?
To state whether a variable is true or false in order to compare.
What does the = operator mean in JavaScript?
It means to assign a value to a variable. For the variable to contain or hold this value.
How do you update the value of a variable?
You assign it to a different value.
What is the difference between null and undefined?
It is a value that is purposely left ambiguous and generally leads to an object. Undefined values are variables that do not have a value.
Why is it a good habit to include “labels” when you log values to the browser console?
The console can display exactly what it is being logged.
Give five examples of JavaScript primitives.
Exercise
Numbers, strings, boolean, null, and undefined.
What data type is returned by an arithmetic operation?
The result of the mathematical operation is returned and contained in the variable, which is numeric.
What is string concatenation?
It is the process of joining together two or more strings and containing it in a variable.
What purpose(s) does the + plus operator serve in JavaScript?
It can add two number values together and it can concatenate two strings.
What data type is returned by comparing two values (, ===, etc)?
A boolean data type is returned, either true or false.
What does the += “plus-equals” operator do?
The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable. (Example: motto = motto + “ is the GOAT”)
What are objects used for?
Objects group together a set of variables and functions to create and organize a model of something. To create subdivision of an object.
What are object properties?
Properties tell us about the object like details. They are key-value pairs.
Describe object literal notation.
Objects are the properties and values within the curly braces and it is stored in a variable. So, it is a set of key-value pairs within curly braces being assigned to a variable. Properties are separated by colons and split by commas.
How do you remove a property from an object?
By using the delete keyword followed by the object name and property name separated by a dot.
What are the two ways to get or update the value of a property?
You can use either the dot notation or square brackets enclosing a set of quotation marks surrounding the property value.
What are arrays used for?
To store a list of similar data.
Describe array literal notation.
A set of values encased in square brackets separated by commas, assigned to a ‘var’ keyword and the variable name.
How are arrays different from “plain” objects?
Arrays are set ordered, they are indexed numerically, there is a constant count of the values in it.
What number represents the first index of an array?
By [0].
What is the length property of an array?
It is the length or number of values in an array.
How do you calculate the last index of an array?
name of the object.length subtracted by 1.
What is a function in JavaScript?
It is a set of instructions(code) that is reusable.
Describe the parts of a function definition.
function keyword, name of the function, parameter list, opening and closing curly braces for the function code block, and a return.
Describe the parts of a function call.
the name of the function with its parameters.
When comparing them side-by-side, what are the differences between a function call and a function definition?
a call has just the function name with a set of (), a definition has the keyword, name, (parameters), and a function code block.
What is the difference between a parameter and an argument?
parameters are placeholders and arguments are actually values.
Why are function parameters useful?
to provide values to the function in order to get a new result.
What two effects does a return statement have on the behavior of a function?
it first returns the output of a function and then it stops the code from running.
Why do we log things to the console?
to verify output and see change over time (debugging)
What is a method?
a function stored in a property.
How is a method different from any other function?
methods are attached to objects. need to specific which object is it being pulled from.
How do you remove the last element from an array?
.pop();
How do you round a number down to the nearest integer?
.floor();
How do you generate a random number?
Math.random() method
How do you delete an element from an array?
.splice( , );
How do you append an element to an array?
.push();
How do you break a string up into an array?
.split();
Do string methods change the original string? How would you check if you weren’t sure?
No, console.log it to the console or check in the console itself.
Roughly how many string methods are there according to the MDN Web docs?
There are 20 ~ 30.
Is the return value of a function or method useful in every situation?
Not always, for example the pop method removes an element of an array
Roughly how many array methods are there according to the MDN Web docs?
There are about 35.
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
===, !==, >=, <=,
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
It evaluates or checks a condition is true or false. (boolean) and to see if it should run the code block.
Is else required in order to use an if statement?
No.
Describe the syntax (structure) of an if statement.
An if statement, then parentheses around the condition, opening curly brace, conditional code block.
What are the three logical operators?
Logical and operator ( &&), logical or operator (| |), logical not operator (!)
How do you compare two different expressions in the same condition?
logical operators “and” or “or”
What is the purpose of a loop?
to check a condition and if it comes back true then the code block will run. If not, it will continue to run until it does get a false result. A way of repeating action for as long as we need.
What is the purpose of a condition expression in a loop?
It is the mechanism to signal a stop in a loop.
What does “iteration” mean in the context of loops?
it a run through of a condition to check the boolean value. One execution of the loop.
When does the condition expression of a while loop get evaluated?
first and before the code block executes
When does the initialization expression of a for loop get evaluated?
when a variable is declared, when the loop first begins.
When does the condition expression of a for loop get evaluated?
before the code block executes and before each interation
When does the final expression of a for loop get evaluated?
after the code block runs and at the end of the condition is met and true.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
the keyword brake
What does the ++ increment operator do?
it increases the integer after each iteration by one
How do you iterate through the keys of an object?
for … in loops
What is the event.target?
the element where the event occured or dispatched from
What is the effect of setting an element to display: none?
hides it from the user (not visible)
What does the element.matches() method take as an argument and what does it return?
it takes a string which is a CSS selector and returns a boolean value if true or not
How can you retrieve the value of an element’s attribute?
element.getAttribute(‘class name’)
At what steps of the solution would it be helpful to log things to the console?
when declaring a variable, changing a variable, running through a loop, conditional and should be done after every step
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
would have to include a addEventListener for each tab and a callback function for each as well
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
would have to include a addEventListener for each tab and a callback function for each as well