I watched a fragment from here
var foo = {n: 1}; var bar = foo; foo.x = foo = {n: 2};
When I write foo.x it says undefined. Why is this so? I expected it to be {n: 2}
Values are assigned from left to right, so this happens:
foo.x = {n: 2};
which leads to the fact that foo is {n: 1, x: {n: 2}}
{n: 1, x: {n: 2}}
then foo is assigned a new value
foo = {n: 2};
which overrides it on {n: 2}.
{n: 2}
foo.x , x foo. 12.14.4 : (ES6, ), , ( ) ( ).
foo.x
x
foo
, :
var foo = {n: 1}; var bar = foo; foo.x = foo = {n: 2}; console.log(foo, bar)
var foo = {n: 1}; var bar = foo; bar.x = foo = {n: 2}; console.log(foo, bar)
var foo = {n: 1}; var bar = foo; foo.x = (foo = {n: 2}); console.log(foo, bar)
Source: https://habr.com/ru/post/1695929/More articles:HTML Javascript dynamically adds and removes text fields - javascriptShould I query and filter on the back-end (Rails API) or front-end (React / Redux) - ruby-on-railsjava.lang.Integer object layout and its overhead - javaWhat is the minimum mating of a Dijkstra tree? - algorithmEmbedding data from a database into a class using ASP.NET MVC Core - c #Waiting will not work even in an asynchronous function - javascriptscatter chart: high arrays eating up all memory - arraysHow to use a range of axes and labels from source data in ggtern? - rХранилище Google облако возвращает старые данные - httpHow to change the labels of a triple chart made by ggtern? - rAll Articles