Data Types Flashcards

1
Q

What are the six primitive data types?

A

number,
string,
boolean,
undefined,
null,
symbol.

These data types are immutable and cannot be modified once they are created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between undefined and null?

A

“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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a symbol data type?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between a primitive data type and a reference data type?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the typeof operator?

A

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”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly