Javascript Short-circuit expression gives confusing result

26 views Asked by At

I am quite confused and don't understand what's going on with the output of this javascript expression evaluation.

let m = 6;
let x=true;

m = m || x ? 10 : 0;
console.log(m); //10

In above example we have m = 6 || 10, so m should be 6 but it outputs 10.

let m = 6;
let x=false;

m = m || x ? 10 : 0;
console.log(m); //10

Similarly in above expression we have m = 6 || 0 which should also output 6 but still it outputs 10.

Can someone please explain what's going on here?

0

There are 0 answers