JavaScript Flashcards
What is the purpose of variables?
To store information, so it can be retrieved later.
How do you declare a variable?
var name;
How do you initialize (assign a value to) a variable?
name = value;
What characters are allowed in variable names?
A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($). Subsequent characters can also be digits (0–9).
What does it mean to say that variable names are “case sensitive”?
Their exact case must match.
What is the purpose of a string?
To hold text.
What is the purpose of a number?
To hold information that relates to arithmetic calculations.
What is the purpose of a boolean?
To check whether a value is true or false and make decisions based on that.
What does the = operator mean in JavaScript?
Assigning a value.
How do you update the value of a variable?
name = newValue;
What is the difference between null and undefined?
Null has been set by the user, while undefined is on the computers end.
Why is it a good habit to include “labels” when you log values to the browser console?
So that you should be able to see clearly what relates to what, and also for the benefit of others.
Give five examples of JavaScript primitives.
number / string / boolean / undefined / null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
Adding a string to another string using +
What purpose(s) does the + plus operator serve in JavaScript?
Concatenation of strings / addition
What data type is returned by comparing two values (, ===, etc)?
Boolean.
What does the += “plus-equals” operator do?
Add new value, and reassigns to the variable.
What are objects used for?
To store properties and methods together.
What are object properties?
Like variables, they contain information about specifics of an object.
Describe object literal notation.
{ }
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
object.property / object[‘property’]
What are arrays used for?
To store lists.
Describe array literal notation.
[ ]
How are arrays different from “plain” objects?
They have a specific order.
What number represents the first index of an array?
0
What is the length property of an array?
How many items the array contains.
How do you calculate the last index of an array?
array.length - 1
Why should arrays have similar data types and structure?
Will be much easier to work with, and loop over.
What is a function in JavaScript?
A recipe, a set of steps.
Describe the parts of a function definition.
function functionName(params) { code optional return }
Describe the parts of a function call.
functionName(params);
When comparing them side-by-side, what are the differences between a function call and a function definition?
function keyword. code block { }
What is the difference between a parameter and an argument?
parameter is a placeholder, no value yet. Argument is when we are giving it a value.
Why are function parameters useful?
To supply additional information, to make it reusable
What two effects does a return statement have on the behavior of a function?
Code stops running there.
Returns a value that can be used.
Why do we log things to the console?
To see if they behave as expected.
What is a method?
A function of an object.
How is a method different from any other function?
Since it belongs to an object, it needs to be called with the object.
How do you remove the last element from an array?
array.pop( )
How do you round a number down to the nearest integer?
Math.floor( )
How do you generate a random number?
Math.random ( )
How do you delete an element from an array?
array.splice(1, 1, add)
How do you append an element to an array?
array.push( )
How do you break a string up into an array?
string.split(‘ ‘)
Do string methods change the original string? How would you check if you weren’t sure?
No
Is the return value of a function or method useful in every situation?
No
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?
To check whether something is true, and do something based on that
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if (expression) {
code
}
What are the three logical operators?
&& / || / !
How do you compare two different expressions in the same condition?
With && ||
What is the purpose of a loop?
To do steps repeatedly until a certain condition is met.
What is the purpose of a condition expression in a loop?
To see whether the loop should continue.
What does “iteration” mean in the context of loops?
Each round
When does the condition expression of a while loop get evaluated?
Before the code block begins
When does the initialization expression of a for loop get evaluated?
First thing
When does the condition expression of a for loop get evaluated?
Before each iteration of the loop
When does the final expression of a for loop get evaluated?
After each iteration of the loop
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
Adds 1