I am a learner. When I try to assign value to a variable as follows it doesn't work. Want to know the reason.
this doesn't work:
const w =
if (2 > 1) {
return 1500;
} else {
return 2500;
}
However this works:
const w = function() {
if (2 > 1) {
return 1500;
} else {
return 2500;
}
}()
Is there a better approach?
returnkeyword is used to return a value from a function not to assign a value to some other variable or constant.