let n; let b = (n =1) +(n=4); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

let n; let b = (n =1) +(n=4);

b is 5 My question is that, isn't the expression (n=4) supposed to change the previous (n=1), which would change n everywhere to 4, which indirectly should make the above expression => let b = 4 + 4 // b === 8 Am i bit confused on why it is not working that way

8th Aug 2021, 10:22 PM
_Zi_
_Zi_ - avatar
1 Answer
+ 5
Ink_ross, let n; b = (n=1) + (n=4); console.log(n); console.log(b); 4 5 Above is output of code, Sub-Expression first evaluated n=1 it returns current value of 1. second Sub-Expression is evaluated n=4 it returns 4. Because first evaluation set n to 1 and second evaluation set n to 4. b = (n=1) + (n=4); b = 1 + (n=4) n = 1 b = 1 + 4 n = 4 b = 5 n = 4 Because of evaluation happens from left to right. This may help DHANANJAY PATEL
8th Aug 2021, 10:53 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar