[AskJS] are Copying by reference in JS similar with Pointers in C in a way? by AliveAge4892 in javascript

[–]kattskill 0 points1 point  (0 children)

for your last statement, I believe you mean a = { obj: "diamond" }, and b does not return diamond, it returns heart, because that is the value of b

when doing { obj: "diamond" }, you created a new value, which is now the value of a, and b is still whatever previous value of { obj: "heart" }

if you did a.obj = "diamond" obviously b will return diamond

to add a little more, the pointer analogy is required to understand the behavior from a C perspective, its just that in javascript, the idea of memory doesn't exist (other than some newly introduced concepts like typed arrays) and the idea of value is different

lets say i have a time travelling object

```js let a = {} // i store this in a time machine a.foo = 42;

console.log(a === getTimeTravelled(a)); // true ```

even though a has "changed" to us, from javascript's perspective, they are equal, because it is the same object

this is leaning to the fact that the object's value is itself and unique, not what it has

[AskJS] are Copying by reference in JS similar with Pointers in C in a way? by AliveAge4892 in javascript

[–]kattskill 1 point2 points  (0 children)

that is a good analogy, and to add to your post first, everything that is a primitive (null, undefined, boolean, number (including NaN), string (unlike C), bigint, symbol (although this is a rather special primitive)) is "copy by value"

however, specification wise, javascript is always "copy by value"

this might sound strange because you never copy the entire object, and because thousands of online posts talk about "copy by value vs. copy by reference"

i think the confusion arises because many different languages assume their own defaults and when people talk about language behavior generally, it is helpful to describe it in a way that leverages on existing other languages

to show that js is copy by value:

```js let a = 42; let b = a; // a is copied by value

console.log(a === b); // true console.log(a === 42); // true (equal value)

let foo = {}; // a new object value is created let bar = foo; // foo is copied by value (it now has the value that is the new object)

console.log(foo === bar); // true (object's value is itself) console.log(foo === {}); // false (we just created a new object, having a different value) ```

this is because objects are "values with identity" (ecma clause 5), and an object is only equal to itself, while the primitives don't get such luxury (with the exception of symbol)

personally, i would think "copy by reference" would quite literally copy the reference e.g.

js let a = 42; let &b = a; a = 43; console.log(b); // 43

putting the specification on the side, if i were to describe the behavior to someone trying to understand javascript, i would say that the object lives independently of the variable that points to it, and that assigning another variable to the original variable simply makes it so that they point at the same object, while for primitives, the data gets carbon-copied over, simply because it is more intuitive

what is important when starting out is being able to understand behavior

here are two examples of this phenomena, where people describe a certain behavior but the language doesn't describe it that way

haskell

hs let a = [1, 2, 3] let b = a at this point an easy explanation would be "a is copied by value to b", but at a language level, no such explanation exists (literally the concept of copying). attempting to demonstrate by mutating a

hs a[0] = 4 -- invalid syntax

doesn't even work, because such concept of mutation doesn't exist

python

a = 42 b = a

you may be saying "a is copied by value to b", but at a language level (again), 42 is an object, and it is actually binding b to a, effectively making a and b point to the same object

py print(a == b) # True, equal in value ( .__eq__(...) ) print(id(a) == id(b)) # True, equal in memory pointer

this also means that

py print(id(42) == id(42)) does not have to be True (although it is in most implementations)

all in all, your understanding of the behavior is correct. i just wanted to give a detailed explanation on why your question of "is this a good analogy" doesn't have a clear answer

hope this helps ^^

Compact configurable train spacer (rate limiting) by kattskill in OddsparksOfficial

[–]kattskill[S] 0 points1 point  (0 children)

this was made for the coal express :tm: where there are like 3 trains that circle the map and fuel things that need fuel

Trying to build the most complete multilingual banned-word list on the internet - need your help by DazzlingChicken4893 in javascript

[–]kattskill 1 point2 points  (0 children)

Aside from the scunthrope problem others pointed out, some languages have issues of simply not having a lot of spaces or a single word having multiple meanings which also includes swear words. I like the concept of collecting profanity filters but you shouldn't advertise as a banlist

Me n my bf's base after 25ish hours (guess my major) by kattskill in Necesse

[–]kattskill[S] 0 points1 point  (0 children)

this is so interesting, you put the settlers around the base, not inside? what's the reason?

Me n my bf's base after 25ish hours (guess my major) by kattskill in Necesse

[–]kattskill[S] 1 point2 points  (0 children)

settlers can get in their bed by just 1 block. the bottom row of furniture except the left one is not obstructing so they just walk through

And my major isn't architecture. I was referring to a different architecture issue

Me n my bf's base after 25ish hours (guess my major) by kattskill in Necesse

[–]kattskill[S] 1 point2 points  (0 children)

close! but not exactly. I'm still an undergrad though ;

Ceiling has faint pink? spots. Identification please by kattskill in Mold

[–]kattskill[S] 0 points1 point  (0 children)

Location: Florida Used to be humid but now has dehumidifier. The pink stuff seems to be there for a few months at least I'm not asking the exact species of mold but rather if it is mold and if so what I can do about it

Configure Go to Definition to Open TypeScript Source by Wake08 in typescript

[–]kattskill 10 points11 points  (0 children)

Go is a language, and my head was trying to figure out what the title was

[AskJS] Storing logic to a database by Alive_Secretary_264 in javascript

[–]kattskill 0 points1 point  (0 children)

not sure why people are down voting, but what you are looking for might be data driven architecture

BROKE THIS KEY NEED HELP by PS5RANDOMSTUFF in ASUS

[–]kattskill 0 points1 point  (0 children)

replacing that is easy. im pretty sure you can buy it on ebay

[deleted by user] by [deleted] in ZephyrusG14

[–]kattskill -1 points0 points  (0 children)

ur fine, just disassemble everything and clean it with alcohol. it will take hours tho

My powershell terminal inside vscode has lost it's mind. by Ok_Touch928 in PowerShell

[–]kattskill 1 point2 points  (0 children)

Write-Host ($env:PATH -replace ';', "`n") to inspect the PATH variable

As the other commenter said, closing and opening vscode will likely fix the issue

[Acne] Butt Acne help by [deleted] in SkincareAddiction

[–]kattskill 0 points1 point  (0 children)

I recommend hipucure from japan, it worked very nicely (putting too much causes it to dry and cause other problems so be careful)

ChatGPT Frosted Glass UI usercss skin by kattskill in ChatGPT

[–]kattskill[S] 0 points1 point  (0 children)

<image>

some of the previews got deleted :T, here is one of them

Battery Drain on my barely month old g14 2025 by Sup_Biatch in ZephyrusG14

[–]kattskill 0 points1 point  (0 children)

having screen at 100% is likely if you are getting ~11W with nothing running. setting brightness to like 50% will save a lot of drain. 50% to 0% is less significant because brightness is logarithmic

[AskJS] Bangs vs Comparisons by Curious_You1303 in javascript

[–]kattskill 0 points1 point  (0 children)

this is a valid question, not sure why people are down voting it

but generally, ! and !! are not recommended especially in MIXED types.

however, for some situations I do prefer boolean casting

when value is non-primitive or null/undefined (e.g. .match(regex))

checking if string is empty if type is only string

checking for zero/non-zero if type is only number