JavaScript Flashcards
What is the purpose of variables?
To store bits of data
How do you declare a variable?
With a variable keyword (var, let, const) followed by the variable name
How do you initialize (assign a value to) a variable?
With an assignment operator (=)
What characters are allowed in variable names?
letters, digits, underscores and dollar signs (CANNOT START WITH NUMBER)
What does it mean to say that variable names are “case sensitive”?
upper and lowercase matter
What is the purpose of a string?
To store text data
What is the purpose of a number?
To store number data
What is the purpose of a boolean?
To identify true or false
What does the = operator mean in JavaScript?
Assignment operator
How do you update the value of a variable?
By calling again with the assignment operator followed by the new value
What is the difference between null and undefined?
Null usually a placeholder
Undefined points at valueless variables
Why is it a good habit to include “labels” when you log values to the browser console?
Describes the variable or value being logged
Give five examples of JavaScript primitives.
String
Boolean
Object
Undefined
Null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
When two or more lines of strings are combined using the addition operator
What purpose(s) does the + plus operator serve in JavaScript?
Adds one value to another
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Adds the value of the right operand to a variable and assigns the result to the variable
What are objects used for?
To represent real world objects
What are object properties?
Information about the object
How do you remove a property from an object?
With the delete operator
What are the two ways to get or update the value of a property?
Dot and Bracket notation
What are arrays used for?
To store list data
Describe array literal notation.
var arrayName = [’’]
How are arrays different from “plain” objects?
Arrays have indexes objects dont
What number represents the first index of an array?
array[0]
What is the length property of an array?
Represents the number of properties in that array
How do you calculate the last index of an array?
array[array.length -1]
What is a function in JavaScript?
A pack of code to reuse
Describe the parts of a function definition.
function funcName(parameter,/…/,parameter) {
code …/
return;
code …/
}
Describe the parts of a function call.
funcName(parameter,/…/,parameter);
When comparing them side-by-side, what are the differences between a function call and a function definition?
No code block
What is the difference between a parameter and an argument?
Arguments are real values being passed to the function, while parameters are just placeholder names
Why are function parameters useful?
Specify what the argument should be
What two effects does a return statement have on the behavior of a function?
Returns the function when being called
Stops the code from running
Why do we log things to the console?
To check our work
What is a method?
Function of an object
How is a method different from any other function?
It’s a property of an object
How do you remove the last element from an array?
With the array.pop(); method
How do you round a number down to the nearest integer?
With the Math.floor() method
How do you generate a random number?
With the Math.random(); method
How do you delete an element from an array?
With the array.splice(index,amount);
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 dont
Roughly how many string methods are there according to the MDN Web docs?
Around 50
Is the return value of a function or method useful in every situation?
No, you may use it later on
Roughly how many array methods are there according to the MDN Web docs?
40-50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
What data type do comparison expressions evaluate to?
Booleans