JavaScript Flashcards
What is the purpose of variables?
Variables store data!
How do you declare a variable?
Use the var, let, or const keyword
How do you initialize (assign a value to) a variable?
Follow the declaration with an “=“ and the value you’d like to assign
What characters are allowed in variable names?
Start with letter, underscore, or dollarsign. Afterwards — numbers are okay. No keywords! No dashes or periods~!
What does it mean to say that variable names are “case-sensitive”
the two variables lovesDogs and lovesdogs are different due to the D / d.
What is the purpose of a string?
Stores text-data, good for manipulation.
What is the purpose of a number?
Stores number-data, good for mathematics
What is the purpose of a Boolean?
Stores true/false data, good for logic
What does the = operator mean in Javascript?
Assignment operator — assigns right value to the left operand
How do you update the value of a variable?
Use the = operator with the variable on the left, and the new value on the right.
What is the difference between null and undefined?
Null is an intentionally empty value, undefined means no value was assigned
Why is it a good habit to include labels when logging values to the console?
When you add multiple console logs it gets confusing pretty quickly what you logging.
Give five examples of JavaScript primitives.
Number, string, Boolean, null, undefined
What is a JavaScript primitive?
A data that is not an object, and hence has no methods or properties.
What data type is retuned by an arithmetic operation?
Number is returned
What is string concatenation?
Joining together two strings and returning a new string
What purpose(s) does the + operator serve in JavaScript?
Adds two operands (not necessarily nums!)
What data type is returned by comparing two values (<, >, ===, etc.)?
Boolean (t / f)
What do the += “plus-equals’ operator do?
Shorthand — adds the value of right side to the left side variable and returns the result
How are reference data types and primitive data types stored differently?
Reference data types only store the memory pointer to that specific data
The two reference data types are…
Objects and arrays
What are objects used for?
To group together variables and functions in order to model something from the real world
What are object properties?
The variables of the object are its properties (its functions are known methods)
Describe object literal notation.
Declare variable and assign it the value of empty curly braces