JavaScript Flashcards
What is the purpose of variables?
the purpose of variables is to store data for future use
How do you declare a variable?
with keyword “var” and an assignment operator and value
How do you initialize (assign a value to) a variable?
with the assignment operator “=”
What characters are allowed in variable names?
letters, numbers, $, and _
What does it mean to say that variable names are “case sensitive”?
it means that
var score
and
var Score
are different
What is the purpose of a string?
to store text
What is the purpose of a number?
to store number data
What is the purpose of a boolean?
to be a light switch
it stores “true” or “false”
and is the logic in JavaScript
What does the “=” operator mean in JavaScript?
it’s the assignment operator and assigns values to variables
How do you update the value of a variable?
with the assignment “=” operator
What is the difference between “null” and “undefined”?
null is an object and intentional. a placeholder
undefined is automatically assigned to a variable
Why is it a good habit to include labels when you log values to the browser console?
to add context to what you’re doing. also makes the data easier to read
Give five examples of JavaScript primitives
null undefined string number boolean
symbol
bigint
What data type is returned by an arithmetic operation?
number
What is a string concatenation?
It’s the combination of two strings by using the “+” operator
What purpose(s) does the + operator serve in JavaScript?
it’s used as addition in arithmetic, as concatenation with strings and variables
What data type is returned by comparing two values (, ===, etc)
boolean
What does the += “plus-equals” operator do?
It adds whatever value is specified to the variable and then reassigns it to the variable
What are objects used for?
They’re used to store related data in one place
What are object properties?
Object properties serve as the “variables” of an object
Describe object literal notation
a list of key value pairs within an object
a key is assigned a value and each pair is separated by a comma
var = {
key: value,
secondKey: value
};
How do you remove a property from an object?
with the “delete” keyword
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What are variables called in an object?
they are called properties