Memory Allocations in JS

Memory Allocation when dealing with JS “Primitives”

let myNumber = 23
Image for post
Image for post
let newVar = myNumber
Image for post
Image for post
myNumber = myNumber + 1
Image for post
Image for post
let myString = 'abc'
myString = myString + 'd'
Image for post
Image for post

JavaScript’s memory model: the call stack and the heap

Image for post
Image for post

Memory Allocation when dealing with JS “non-Primitives”

let myArray = []
Image for post
Image for post

Let vs. const

let sum = 0
sum = 1 + 2 + 3 + 4 + 5let numbers = []
numbers.push(1)
numbers.push(2)
numbers.push(3)
numbers.push(4)
numbers.push(5)
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Why is it OK to declare an array using “const” ?

const myArray = []
Image for post
Image for post
myArray.push(1)
myArray.push(2)
myArray.push(3)
myArray.push(4)
myArray.push(5)
myArray = 3
myArray = ['a']
const myObj = {}
myObj['newKey'] = 'someValue' // this will not throw an error

Google Recommendation:-

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store