JavaScript Flashcards
What is the purpose of variables?
to store data (temporarily) that can be accessed later
have a value that persists
How do you declare a variable?
var variableName;
How do you initialize (assign a value) to a variable?
var variableName = (variable value);
What characters are allowed in variable names?
letters, numbers, dollar signs, underscore
no dash or period
cannot start with a number
What does it mean to say that variable names are “case sensitive”?
score != Score
What is the purpose of a string?
store data with text content
save a series of characters
What is the purpose of a number?
count, math, measurement
What is the purpose of a boolean?
to make decisions
determine which part of a script should run
What does the = operator mean in JavaScript?
assignment operator
assigns a value to a variable
updates value given to a variable
How do you update (reassign) the value of a variable?
using equal sign (assignment operator) to assign it a new value
var is only necessary the first time
What is the difference between null and undefined?
null means no value
undefined means variable has not been declared/given a value
null MUST be assigned
Why is it a good habit to include “labels” when you log values to the browser console?
to know which value or variable is being logged
helpful for catching bugs
Give 5 examples of JavaScript primitives
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
a number (always)
What is string concatenation?
combination of two or more string values (or number)
What purpose(s) does the + operator serve in JavaScript?
adds on value to another or concatenation
What data type is returned by comparing two values?
a boolean true or false
What does the += operator do?
adds the value of the value on right to the current variable and assigns the result to that variable
What are objects used for?
storing a set of variables and functions
bringing data together
create a collection of stuff that make sense
What are object properties?
individual pieces of data stored in an object
Describe object literal notation
The object which contains a set of properties and values inside curly braces being assigned to a variable
How do you remove a property from an object?
Use the delete operator followed by the object and property name
What are the two ways to get or update the value of a property?
dot or bracket notation
What are arrays used for?
storing a list or set of values that are related to each other