jeudi 27 février 2020

Javascript console.log weird behavior on browser console

If i run the following code on chrome or firefox directly into the console, on the first log the value of value2 is 0 in the inlined representation, but if I expand the representation to check the whole object, it is showed as 17. Is this a multi browser bug or I am missing something with javascript here? The reason I am asking this question here is because this behaviour is happening across different browsers, which makes me think there is some kind of catch on the language or the function that I am not aware of.

Actual code:

action = new Object();
action.value1 = 17;
action.value2 = 0;

console.log(action);
action.value2 = action.value1;
console.log(action);

Tested on MacOS Catalina with the latest version of both browsers.

EDIT-----------------

The problem is the first console.log prints value2 being 0 but when I expand the object details it is showed as 17. I attached a print to clarify the question.

PRINT OF THE CONSOLE RESULTS

I would expect the result to be 0 on the value2 of the first output even with the expanded view.




Aucun commentaire:

Enregistrer un commentaire