primitives-and-variables Flashcards
What is the purpose of variables?
Variables store text content in a name.
Variables are containers for storing data
This allows us to be able to reference some variable instead of some possibly long value for snippet string thats complex and long.
How do you declare a variable?
You declare a variable using the var keyword followed by the name of the variable followed by a semicolon.
How do you initialize (assign a value to) a variable?
You assign the ${ unknown-value}
to ${ user-defined-name}
What characters are allowed in variable names?
[azAZ]||[any:number]||
||[any: symbol]||
underscore any entity
JavaScript can handle many types of data.
Since JavaScript treats a dollar sign as a letter, identifiers containing $ are valid variable names:
Using the dollar sign is not very common in js, but professional programmers often use it as an alias for the main function
Strings are written inside double or single quotes. Numbers are written without quotes.
What does it mean to say that variable names are “case sensitive”?
a vs A are not considered same.
Case matters.
What is the purpose of a string?
a string value is text content of some length
What is the purpose of a number?
a numerical value can be used for arithmetic
What is the purpose of a boolean?
a true or false value can be used for making a decision.
What does the = operator mean in JavaScript?
The = operator is used to assign values/ return to a variable
How do you update the value of a variable?
What is the difference between null and undefined?
null is kind of like a state of nothing but its a possible state of nothing. its allowed to exist. eg. just because a baby has not yet been created or born yet, that doesnt mean baies cant exist, they just dont exist yet.
whereas undefined is also a state of nothing but it CANNOT exist its undefined, theres no way to even to define it if it were to exist.
Why is it a good habit to include “labels” when you log values to the browser console?
it allows you to correlate meaning to the value.
Give five examples of JavaScript primitives.
string
number
boolean
null
symbols?
undefinded?