📘
snesjhon
  • You Should Know
  • Personal
    • Blogs
      • I'll never complain about web tooling again.
      • vscodevim
  • JavaScript
    • Closures
      • Closure Q1
    • Values
      • Primitive vs Reference
      • Accessing by value and reference
    • Function
      • call, apply, bind
      • Pass by value
      • Different types of Scopes
      • Context vs Scope
      • Parse Time Vs Run Time
    • Hosting
      • Are Let & Const Hoisted?
      • Hoisting Q1
      • Hoisting Q2
    • Standard Objects
      • Math
        • Math.log10
        • Math.pow()
    • Array
      • Apply
      • Slice vs Splice vs Split
    • This
      • This - Q1
    • TypeScript
      • as const
    • FAQs
      • Modulo Operator
      • Timeout
      • Declarative vs Imperative
      • ++i vs. i++
    • Interview Questions
  • react
    • FAQs
  • Ruby
    • Debugging
    • Symbols
    • Intro
  • Algorithms
    • Sliding Window
      • minSubArrayLen
      • maxSubArraySum
      • findLongestSubstring
    • Frequency Counter
      • sameFrequency
    • Recursion
      • nestedEvenSum
      • flatten
      • Reverse a String
      • Fibonnacci
    • Searching
      • overlappingIntervals
      • twoStringSearch
      • binarySearch
    • Sort - Elementary
      • Selection Sort
      • Bubble Sort
      • Insertion Sort
      • quickSort
    • Sort - Intermediate
      • Radix Sort
      • Merge Sort
    • FAQs
  • Data Structures
    • Breadth First Search
    • Linked Lists
      • Singly Linked Lists
    • FAQs
  • Code Challenges
    • LeetCode
      • removeDuplicates
    • Hacker Rank
      • twoSums
      • Sock Merchant
    • Hacker Rank - Medium
      • New Year Chaos
  • Databases
    • SQL
Powered by GitBook
On this page
  • 7 Primitives (Data Types)
  • Objects (Reference Type)
  • Functions
  1. JavaScript
  2. Values

Primitive vs Reference

Last updated 4 years ago

In JavaScript, a variable may store two types of values:

Primitives and Reference

7 Primitives (Data Types)

  • Undefined:

    • Only one value, undefined.

  • Null:

    • Only one value, null.

  • Booleans:

    • Two values: true and false.

  • Numbers:

    • One value for each number.

  • BigInts:

    • One value for every conceivable integer.

  • Strings:

    • One value for every conceivable string.

  • Symbols:

    • More on this later

The size of a primitive value is fixed, therefore, JS stores the primitive value on the stack

Objects (Reference Type)

  • One value for every object literal we execute

  • A non-data type

  • Structural Type

The size of a reference value is DYNAMIC so JS stores the reference value on the heap

Functions

  • One value for every function expression we execute.

  • Structural Type

Resource:

floating point math
https://www.javascripttutorial.net/javascript-primitive-vs-reference-values/