0% found this document useful (0 votes)
6 views

Primitive Types and Reference Types

Primitive types in JavaScript, such as numbers and booleans, have a fixed size in memory, while reference types, including objects, arrays, and functions, do not have a fixed size. Primitive types can be directly stored in memory, whereas reference types store a reference to the value, typically as a pointer or memory address. This distinction affects how variables hold and access different types of data.

Uploaded by

vickyrocker
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Primitive Types and Reference Types

Primitive types in JavaScript, such as numbers and booleans, have a fixed size in memory, while reference types, including objects, arrays, and functions, do not have a fixed size. Primitive types can be directly stored in memory, whereas reference types store a reference to the value, typically as a pointer or memory address. This distinction affects how variables hold and access different types of data.

Uploaded by

vickyrocker
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Primitive Types and Reference Types

Numbers, boolean values, and the null and undefined types are primitive. Objects, arrays, and
functions are reference types.

Primitive Types
A primitive type has a fixed size in memory.
For example, a number occupies eight bytes of memory, and a boolean value can be
represented with only one bit.
The number type is the largest of the primitive types.
If each JavaScript variable reserves eight bytes of memory, the variable can directly
hold any primitive value.

Reference types
Reference types are another matter, however. Objects, for example, can be of any
length -- they do not have a fixed size.
The same is true of arrays: an array can have any number of elements.
Similarly, a function can contain any amount of JavaScript code.
Since these types do not have a fixed size, their values cannot be stored directly in the
eight bytes of memory associated with each variable.
Instead, the variable stores a reference to the value. Typically, this reference is some
form of pointer or memory address.
It is not the data value itself, but it tells the variable where to look to find the value.

You might also like