0

Javascript if clause

Suppose: var a = 30; var b = 5; var zero = a%b; if(zero) console.log(10); else console.log(20); Hi class, in my opinion, the output must be 20, because if(zero) is equals to if(0), so the statement(s) inside else clause will be executed. What is your opinion.

22nd Apr 2024, 3:32 AM
Oliver Pasaribu
2 ответов
+ 1
Is this a quiz question? You need to understand from this, but not a direct answer. The if statement evaluates the condition inside the parentheses. If the condition is truthy, meaning it's not zero, undefined, null, false, NaN, or an empty string (""), then the code inside the if block will be executed. Now understand this case: https://sololearn.com/compiler-playground/c90EBEbV2RBJ/?ref=app
22nd Apr 2024, 4:38 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
Yes, that's right.
22nd Apr 2024, 8:00 AM
Oliver Pasaribu