Javascript Flashcards
What is the purpose of variables?
To give us a location to store data to use in the future
How do you declare a variable?
By using var, setting a variable name, then using the = operator to set it to a value
How do you initialize (assign a value to) a variable?
Using the = operator
What characters are allowed in variable names?
Letters, numbers, dollar sign, underscore
What does it mean to say that variable names are “case sensitive”?
It is sensitive to capitalizations
What is the purpose of a string?
To store text
What is the purpose of a number?
To store a numerical or mathematical value
What is the purpose of a boolean?
To store a true or false value
What does the = operator mean in JavaScript?
It’s used to set a variable to a value (assignment operator)
How do you update the value of a variable?
State the variable name, assignment operator, set it to new value
What is the difference between null and undefined?
Null is an assigned value and explicitly means nothing. Undefined means a variable has been declared, but the value has not yet been defined
Why is it a good habit to include “labels” when you log values to the browser console?
It adds readability and gives more context
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
A number data type
What is string concatenation?
When you combine multiple strings using the + operator
What purpose(s) does the + plus operator serve in JavaScript?
To perform addition or concatenate multiple strings together to create one value
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
A shorthand operator that allows you to add the value from the right operand to the left operand, then assigns the new value to the left operand
What are objects used for?
To store multiple data points or properties within a variable
What are object properties?
A collection of values attached to an object
Describe object literal notation.
A variable assigned to multiple properties using curly brackets, then a list of properties and their values separated by a colon, comma to separate multiple properties.
How do you remove a property from an object?
Keyword “delete” then the object.property or object[‘property’]
What are the two ways to get or update the value of a property?
getAttribute, setAttribute
What are arrays used for?
To store a list of elements that we can access by a single variable. To-do lists, lists of users, etc are all great ways to leverage arrays