0

Could you explain what does this code mean?

let a; let b=null; let c=4; let d='five'; let e=a||b||c||d; alert(a); /* the output in text editor is undefined but I got this question from js quizes, the answer in quiz is 4 what is the correct answer and what does || mean? */

18th Aug 2019, 2:23 PM
Safaa Alnabhan
Safaa Alnabhan - avatar
1 Odpowiedź
+ 2
4 would not be the correct answer for what you've written here, but if the alert on js quizzes was for e, then it would be 4. a||b||c||d is setting e to the first variable that isn't false. || Means OR. a is undefined and that is falsey in js. Same for b and null. c is the first value that isn't false, but if you change it to 0, you might get 'five' as the answer instead.
18th Aug 2019, 2:40 PM
Zeke Williams
Zeke Williams - avatar