JavaScript Flashcards
What is the purpose of variables?
So the computer has a temporary location to store data.
How do you declare a variable?
With the keyword ‘var’.
How do you initialize (assign a value to) a variable?
By using the assignment operator. ( = )
What characters are allowed in variable names?
No special characters besides $ or _. No spaces.
What does it mean to say that variable names are “case sensitive”?
Name and name are two different variables.
What is the purpose of a string?
To store a sequence of characters. Can be used when working with any kind of text.
What is the purpose of a number?
For tasks that involve calculations.
What is the purpose of a boolean?
To help determine which part of a script should run.
What does the = operator mean in JavaScript?
The assignment operator in JavaScript means the data on the right is being assigned to the variable on the left.
How do you update the value of a variable?
By using the assignment operator.
What is the difference between null and undefined?
Null is intentionally assigned to no value;
While undefined has not yet been assigned a value.
Why is it a good habit to include “labels” when you log values to the browser console?
To make debugging easier.
Give five examples of JavaScript primitives.
Number, string, boolean, null, undefined, symbol, bigInt.
What data type is returned by an arithmetic operation?
Number.
What is string concatenation?
Combining two or more strings into one.
What purpose(s) does the + plus operator serve in JavaScript?
Addition and Concatenation.
What data type is returned by comparing two values (, ===, etc)?
Boolean.
What does the += “plus-equals” operator do?
Adds whatever number is on the right to the variable on the left, and then assigns that result to the variable.
What are objects used for?
To organize a set of variables and functions under one reusable item.
What are object properties?
A variable within an object.
Describe object literal notation.
Curly brackets with all properties and methods inside, separated by commas.
What are the two ways to get or update the value of a property?
Using dot or bracket notation.
How to you remove a property from an object.
The delete operator.
What are arrays used for?
To store ordered lists of data.
Describe array literal notation.
[ … , … , … , … ]
How are arrays different from “plain” objects?
Arrays are ordered and can be accessed numerically.
What number represents the first index of an array?
0
What is the length property of an array?
Determines how many items are in the array. Based on memory indexes.
How do you calculate the last index of an array?
Length of the array minus one.
What is a function in JavaScript?
A “formula” used as a way for us to repeat code throughout our program without having to type that code out each time.
Describe the parts of a function definition.
function keyword, followed by an optional name, parameters enclosed in parentheses, code-block enclosed with curly-braces.
Describe the parts of a function call.
The function name, followed by parentheses and any necessary parameters.
When comparing them side-by-side, what are the differences between a function call and a function definition?
The code-block does not run when a function is defined, only when it is called.
What is the difference between a parameter and an argument?
A parameter is a placeholder variable inside a function definition. An argument is a variable passed to a function when it’s called.
Why are function parameters useful?
So we can change the data we give to our functions.
What two effects does a return statement have on the behavior of a function?
It causes the function to end, and returns a value in it’s place.
Why do we log things to the console?
To assist in debugging.
What is a method?
A function within an object.
How is a method different from any other function?
It is within an object.
How do you remove the last element from an array?
With the pop( ) method.
How do you round a number down to the nearest integer?
With the floor( ) method of the Math object.
How do you generate a random number?
With the random( ) method of the Math object.
How do you delete an element from an array?
With the splice( ) method.
How do you append an element to an array?
With the push( ) method.
How do you break a string up into an array?
With the split( ) method
Do string methods change the original string? How would you check if you weren’t sure?
They do not; And you could console log the original string after to be sure.
Roughly how many string methods are there according to the MDN Web docs?
A LOT.
Is the return value of a function or method useful in every situation?
Not in every situation. Such as console.logs.
Roughly how many array methods are there according to the MDN Web docs?
A LOT.
Give 6 examples of comparison operators.
==, ===, , <=, >=
What data type do comparison expressions evaluate to?
Boolean values.
What is the purpose of an if statement?
To check a condition before running a segment of code.
Is else required in order to use an if statement?
No.
Describe the syntax (structure) of an if statement.
if ( condition ) { conditional code-block };
What are the three logical operators?
AND ( && ), OR ( || ), NOT ( ! )
How do you compare two different expressions in the same condition?
By using logical operators.
What is the purpose of a loop?
To repeat segments of code.
What is the purpose of a condition expression in a loop?
To check if the loop should continue.
What does “iteration” mean in the context of loops?
Each time the loop is run is 1 iteration.
When does the condition expression of a while loop get evaluated?
Before the loop runs.
When does the initialization expression of a for loop get evaluated?
The initialization is the first thing to get evaluated in a loop. Only happens once.
When does the condition expression of a for loop get evaluated?
Before the loop is run.
When does the final expression of a for loop get evaluated?
After the loop has run, unless otherwise specified.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break