JS primitives and variables Flashcards
What is the purpose of variables?
store bits of information/store data to be used in the future
How do you declare a variable?
variable keyword and name of variable
ex) var fullName
How do you initialize (assign a value to) a variable?
equal sign ex) var fullName = 'Marley Doughty'
What characters are allowed in variable names?
letters, $, underscore_, numbers (but CANNOT start with number)
What does it mean to say that variable names are “case sensitive”?
uppercase and lowercase are treated as separate entities
ex) fullName !== FullName
What is the purpose of a string?
storing and manipulating text
What is the purpose of a number?
math- determine quantities, dimensions, time
What is the purpose of a boolean?
determine if a value is true or false
What does the = operator mean in JavaScript?
assignment operator, assigns value to a variable
How do you update the value of a variable?
variable name then assign new value ex) var totalPets = 2; (new value is 3 pets) totalPets += 1;
What is the difference between null and undefined?
null is intentional absence like a placeholder meaning no value, whereas undefined is an absence of a value , no value has been assigned or the variable has not been declared
Why is it a good habit to include “labels” when you log values to the browser console?
adds a message in the log that helps maintain organization of variable values, reminds you where it came from (easier to debug)
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null