Skip to content

Instantly share code, notes, and snippets.

@SantoshCode
Last active December 17, 2021 16:23
Show Gist options
  • Save SantoshCode/480cf43d4251997121e99f7e3f83e0ac to your computer and use it in GitHub Desktop.
Save SantoshCode/480cf43d4251997121e99f7e3f83e0ac to your computer and use it in GitHub Desktop.

Mutable

Mutable is a type of variable that can be changed.

Immutable

Immutables are the objects whose state cannot be changed once the object is created.

If an item is mutable, modifying the copy also modifies the original.

example,

  var arr1 = [1, 2, 3]
  var arr2 = arr1
  
  arr2.push(4)
  
  console.log(arr1) // [1, 2, 3, 4]

If it’s immutable, modifying the copy does not affect the original.

example

var a = 1
var b = a
b = b + 1
console.log(a) // 1 a is same
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment