this post was submitted on 03 Aug 2023
970 points (97.1% liked)

Programmer Humor

32054 readers
1519 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] EatBorekYouWreck 1 points 1 year ago

What I think he meant is that in JS every object is a reference or a pointer. This means that instead of the variable be the place in memory where the data is, the variable holds the address of where the data lives. This helps languages like JS and Python have variables that changes their types (you can assign a=true and later a=3 and everything will be fine). A non reference variable, as you can find in languages like C and Rust, is defined by its memory size statically, and the program can just pre-allocate a continuous block of memory that is enough for all the needed variables. This helps your cpu cache and access variables more efficiently. In reference types, memory can end up anywhere on your memory because it is allocated dynamically at runtime, so you access whatever memory that is free and available at the moment. Also the extra step of following a pointer just to get to a block containing a boolean (literally just one bit of memory) compounds and adds up to be actually noticeable in long calculations.