Skip to content

Commit ee7b83d

Browse files
committed
Q23 is improved thanks to @viktmv in ganqqwerty#23
1 parent a4a95c4 commit ee7b83d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,23 @@ console.log(person);
771771

772772
The output of above code would be `USA`. Here `new User("xyz")` creates a brand new object and created property `location` on that and `USA` has been assigned to object property location and that has been referenced by the person.
773773

774-
Let say `new User("xyz")` crated a object called `foo` and returned now `foo["location"]` would be assigned value as `USA` and `person` is referencing to `foo["location"]`.
774+
Let say `new User("xyz")` created a object called `foo`. The value `"USA"` will be assigned to `foo["location"]`, but according to [ECMAScript Specification](http://www.ecma-international.org/ecma-262/6.0/#sec-assignment-operators-runtime-semantics-evaluation) , pt 12.14.4 the assignment will itself return the rightmost value: in our case it's `"USA"`.
775+
Then it will be assigned to person.
776+
777+
To better understand what's going on here, try to execute this code in console, line by line:
778+
```javascript
779+
function User(name) {
780+
this.name = name || "JsGeeks";
781+
}
775782

783+
var person;
784+
var foo = User("xyz");
785+
foo["location"] = "USA";
786+
// the console will show you that the result of this is "USA"
787+
788+
```
789+
790+
776791
## Question 24. Suggest your question!
777792

778793

0 commit comments

Comments
 (0)