javascript-primitives-and-variables Flashcards
What is the purpose of variables?
to store data/info for the script
How do you declare a variable?
var name; keyword is var and following it is the variable name
How do you initialize (assign a value to) a variable?
variableName = x;
assign a value (x) to the variable name using the assignment operator
What characters are allowed in variable names?
dollarsign ($) and underscore (_), letters and numbers
What does it mean to say that variable names are “case sensitive”?
the cases (capital letters, lowercase letters) matter; so “Yes” and “yes” would be different variable names
What is the purpose of a string?
to put any value inside of quotation marks; text values
What is the purpose of a number?
to input numbers as values
What is the purpose of a boolean?
it has two values: true or false; it is to tell whether to run a script or not to make decisions
What does the = operator mean in JavaScript?
it is the assignment operator, meaning it will assign a value to a variable
How do you update the value of a variable?
input the variable name and assign it the new value; no need to declare the var again. Ex: name = “newValue”
What is the difference between null and undefined?
null is when someone actually declared a variable as a null value, while undefined hasn’t been defined by anyone and so has no value
Why is it a good habit to include “labels” when you log values to the browser console?
to be able to tell what the value is for; easier to debug