Home > OS >  Javascript syntax
Javascript syntax

Time:12-13

Can anyone explain the meaning of the assign operator? What does it mean? It came out as true but I'm unclear on how we reached to there.

Thanks!

var x = 0 !=1;

CodePudding user response:

Order of operations (var x = (0 != 1))

Imagine you computed just 0 != 1. This is evidently a true statement, so this would evaluate to true. If you set x to the evaluation of 0 != 1, then you receive var x = true.

CodePudding user response:

An assignment operator assigns a value to its left operand based on the value of its right operand. In this case true will be assigned to the variable x as 1!=0 (1 not equal-to 0) is true.

  • Related