Email or username:

Password:

Forgot your password?
Top-level
Hazel :pleadingcat:

to answer questions about increasing the length & using negative values:

11 comments
Lily

@h
> const array
> modifies it

wtf javascript

yea ik it's probably shallow immutably like zig..

but that implies that the length is stored behind a pointer??

Hazel :pleadingcat:

@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

Hazel :pleadingcat:

@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 :pleadingcat:

@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?

rini ☔

@lily @h const in js is a lie, it only means you can't reassign to the variable
an array is just an object, so you can mutate any property in it (or even add more, which is honestly more cursed)

rini ☔

@lily @h node even displays that properly oml

Hazel :pleadingcat:

@rini @lily yep, its just showing all key value pairs of the array and hiding the numbered keys. and those keys are actually strings btw not numbers, kinda

rini ☔

@h @lily yeah the indices are all treated as strings (but optimised internally). by the spec arrays are "exotic objects", which means their impl can do weird things (length being set automatically when indices are added)

also fun fact most array methods dont actually require an array, so you can do [].join.call({ 0: "a", 1: "b", length : 2 }, ", ")

IAG

@rini @lily @h Java's final qualifier is the same

Go Up