+ 1

Why this code given error?

var value = 0; if(value){ return true; } else { return false; }

29th Jun 2022, 8:29 AM
Romjan Ali
Romjan Ali - avatar
3 Answers
+ 4
Romjan Ali Return should be inside function Break should be inside loop or switch
29th Jun 2022, 8:45 AM
AÍąJ
AÍąJ - avatar
+ 1
var value = 0; if(value){ console.log(true); } else { console.log(false); }
29th Jun 2022, 8:51 AM
SAN
SAN - avatar
+ 1
To return something you need a function. Above code will be like this, var value=0; function tf(){ if(value){return true}else{return false} } console.log(tf()) or simply call the function tf()
5th Jul 2022, 3:46 PM
Nabid Ahammed Limon
Nabid Ahammed Limon - avatar