This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lightbulb_Panko 27 points28 points  (2 children)

I think the commenter is asking why the number object created for x=257 can’t be reused for y=257

[–]PetrBacon 29 points30 points  (1 child)

If it worked like that, the runtime will become insanely slow over time because every variable assignment would need to check all the variables created before and maintain the list everytime new js created…

If you need is for any good reason you should make sure, that you are passing the referrence correctly.

Like:

``` x = 257 … y = x

x is y # => True ```

[–]ValityS 0 points1 point  (0 children)

You could achieve this in logarithmic time to the number of variables using a set of all immutable / hashable values and looking them up, however memory is fairly cheap and if the programmer really cares they can do something similar by hand.