Lazy Evaluation

Joined
Feb 15, 2021
Messages
99
Reaction score
0
i would think this is simple...

Code:
let a = 0; // declare the variable a and assign the value of 0<< 0

false && (a = 1); // (a = 1) is truthy, but it won't be evaluated, since the first operand is false<< false

a // the value of a is still 0<< 0
false || (a = 1); // this will evaluate both operands, so a will be assigned the value of 1, which is returned<< 1

if
Code:
a = 0
, declared first, how can
Code:
a = 1
be truthy?
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
In this statement: false || (a = 1); you set a equal to 1. The single '=' assigns a value to the variable 'a'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top