Email or username:

Password:

Forgot your password?
28 comments
hazel

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

screenshot from NodeJS’s REPL. Increasing the array length adds empty items to the array (not undefined or null, and not an empty string, but an empty item, which you may know also occurs with [,,,,,]) and setting a negative value throws an error.
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

@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

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

an array with two items having an `x` property set to 0
when displayed, the property shows up inside the array as if it was in object notation, even though that's invalid syntax
hazel

@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

demonstration that changing the 0th item of an array not with the number 0 as the key but with the *string* "0" works
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

coolelectronics

@h@social.besties.house this is also a nice way to end up with an array containing empty slots, which behave in very fun and unpredictable ways. javascript may be my favourite language ever

IAG

@h Javascript is a fantastic programming language with no flaws whatsoever

hazel

@freeplay its not bad its just odd. at least in my opinion. its another strange thing i wouldnt expect but not an actual problem

:ball: :kotek:

@h JS should replace all languages by 2026

Artemesia

@h

I was poleaxed the first time I saw the !!! javascript operator, and then researched it and learned it's actually useful in context. Fuck ECMA-script. Second worst thing in the software world, after Windows.

hazel

@artemesia idk what youre talking about with triple exclamation? thats just the same as one-
!true == false
!!true == true
!!!true == false

Artemesia

@h

The first two !! do a type conversion to binary. The third inverts the binary value. The combination lets you do a C-style conditional of "not that, whatever it is".

I wish I didn't know this, and I wish javascruff wasn't such a shitty language.

hazel

@artemesia this isnt part of the language. this is an engine optimisation

hazel

@artemesia before wasm engines had things like this to make javascript run faster by being able to make much more drastic optimisations

hazel

@artemesia you try it??? it does the same thing as one exclamation point as far as a dev is concerned?

Go Up