Email or username:

Password:

Forgot your password?
Top-level
hazel

@lily arrays and objects do this in js yes. what const means is you cannot change it with the = statement. you can push to an array, pop elements off, you can access properties of objects and methods on them and change all of them- but you cant go and do obj = {something: “else”}. practically its constant for numbers and strings.
However- there is a way to have it constant at a deeper level: developer.mozilla.org/en-US/do

2 comments
hazel

@lily
const obj = {}
obj.whatever = “i can do this”
obj = { butICannot: “do this” }

const arr = []
arr.push(“this is fine!”)
arr = [“but this will throw.”]

it is Just the = on the variable itself, none of its fields or anything is constant

hazel

@lily what i find more weird honestly is how strict strings and numbers are. cause- why doesnt this work? strings are arrays of characters why are they more constant than normal arrays?

a constant string str with the text “jello” is created. str[0] is used to edit the first character of the string to swap it for an “h”, but while this does not throw, it does not work either
Go Up