JS Primitives & Variables Flashcards
What is the purpose of variables?
To store data. Data is able to continue to exist under a name and can be referred back to.
How do you declare a variable?
First use a variable keyword (such as “var” or “let” or “const”) and then followed by a variable name.
How do you initialize (assign a value to) a variable?
By using the assignment operator (=): (i.e. var name = value)
What characters are allowed in variable names?
Must begin with a letter, $, or _.
Cannot start with a number.
Cannot use dash ( - ) or period ( . ).
What does it mean to say that variable names are “case sensitive”?
The computer will read the variable as a different variable even with one letter off. Uppercase and lowercase are different.
What is the purpose of a string?
To store characters that have meaning somewhere but not in JavaScript.
What is the purpose of a number?
For tasks that involve counting or calculating sums.
Also for moving elements or resizing elements.
What is the purpose of a boolean?
It was two values “true” or “false”. It serves as kind of like a light switch — can turn on or off a script.
What does the = operator mean in JavaScript?
It is an assignment operator. It does not mean equal. ( === means equal )
How do you update the value of a variable?
It will not need a variable keyword anymore. Simply state the variable name followed by the assignment operator and the new value.
What is the difference between null and undefined?
Null is an object and undefined is undefined.
Null is purposely put there by a developer indicating something will be put there later.
Undefined is from computer.
Why is it a good habit to include “labels” when you log values to the browser console?
So you or other developers know which variable or value is being logged.
It can be less confusing when debugging.
Give five examples of JavaScript primitives.
String, number, boolean, undefined, null