javascript-primitives-and-variables Flashcards
What is the purpose of variables?
To temporarily store the bits of information a script needs to do its job
How do you declare a variable?
Variable keyword, then variable name
How do you initialize (assign a value to) a variable?
Variable name, assignment operator (equal sign), variable value
What characters are allowed in variable names?
Letters, numbers (cannot start with a number), dollar sign, underscore
What does it mean to say that variable names are “case sensitive”?
Variables that have the same name, but one with an upper case and one with a lower case are considered different variable names (ex: Score and score)
What is the purpose of a string?
Stores characters and words. To work with any kind of text
What is the purpose of a number?
Stores numeric values. For tasks that involve counting or calculating sums; can also determine the size of the screen, move the position of an element on a page, or set the amount of time an element should take to fade in
What is the purpose of a boolean?
Stores true or false. Determining which part of a script should run (like turning a switch on/off)
What does the = operator mean in JavaScript?
It is the assignment operator; it says that you are going to assign a value to the variable or update the value given to the variable
How do you update the value of a variable?
Write the variable name that you want to change the value for, the assignment operator, and then the new value you want to give the variable
What is the difference between null and undefined?
Null represents something (an intentionally empty value) nonexistent or invalid; undefined is automatically assigned to variables that have just been declared or that have no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels make it clearer which variables are being logged and in what order
Give five examples of JavaScript primitives.
Numbers, strings, booleans, undefined, null