Variable assignment

M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zm. M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zM8 15. The result was “bar” being displayed in an alert. That is fair enough, a and b are really just aliases to the variable assignment object.

Then I thought, how could I make this example simpler. That is pretty much the same thing, isn’t it? Well this time, it returns foo not bar as I would expect from the behaviour of the first example. In the first example, you are setting a property of an existing object. In the second example, you are assigning a brand new object. This has no effect on what a pointed to before. It’s best to think of variables as pointers to objects, and when you assign directly to a variable, you are not modifying any objects, merely repointing your variable to a different object.

But assigning a property, like a. This, of course, also modifies all other references that point to this object simply because they all point to the same object. No, don’t use the word object. Maybe strings aren’t technically of the javascript type “Object”, but they can be thought of objects in the OO sense. Squeegy: strings are primitives, not objects: you can’t assign arbitrary properties to strings! But strings have methods and properties, and String’s prototype can definitely be modified.

As Christoph explained, this is due to autoboxing. But if you declare it via a string literal, then they are string primitives. Your question has already been satisfyingly answered by Squeegy – it has nothing to do with objects vs. Strings, numbers and booleans as well as null and undefined are primitives, objects are everything which can have properties. Even arrays and functions are regular objects and therefore can hold arbitrary properties. The reason that primitive values may behave like objects is because of autoboxing, but the primitives themselves can’t hold any properties.

This will output undefined: a holds a primitive value, which gets promoted to an object when assigning the property foo. But this new object is immediately discarded, so the value of foo is lost. As such, they are similar to”, then follows with a list of dictionaries, hash, hash tables, and hash maps from various programming languages. The same page describes object property references as hash table lookups. You’re more or less correct except that what you’re referring to as a “hash” is actually just shorthand syntax for an Object. In the first example, a and b both refer to the same object. In the second example, you change a to refer to something else.