Data Types Flashcards
What are the six primitive data types?
number,
string,
boolean,
undefined,
null,
symbol.
These data types are immutable and cannot be modified once they are created.
What is the difference between undefined and null?
“undefined” and “null” both represent the absence of a value.
“undefined” - primitive data type , default value of a variable that has not been assigned a value
“null” - object , must be assigned explicitly
What is a symbol data type?
It’s a primitive data type that represents a unique identifier
Symbols are created using the Symbol() function and are guaranteed to be unique.
Symbols are often used to create private object properties or to provide custom string representations for objects.
What is the difference between a primitive data type and a reference data type?
primitive data types - stored directly in variables
reference data types (object, array, and function) - stored as references to memory locations.
When you assign a variable to a primitive value, you are copying the actual value.
When you assign a variable to a reference value, you are copying a reference to the value.
What is the typeof operator?
It’s a built-in operator that returns the data type of a variable or expression.
It returns a string that corresponds to the data type of the operand.
Example:
typeof 42 // “number”
typeof “hello” // “string”.