Reputation: 323
I'm trying to understand how this line of code works. Apparently, isReady
will return true
if the value for LAUNCH
is 'ready'
and false
if not. What is happening here?
const LAUNCH = 'ready'
const isReady = LAUNCH === 'ready'
Upvotes: 1
Views: 44
Reputation: 8209
To add to the correct answer, the order of evaluation makes all the difference in the world.
The following snippet of code aims to help you better understand how things are evaluated in JS:
var obj = {
true: "stuff"
}
var stuff = function () {
return function () {
return 2+2
}
}
window[obj["hi".length == 2]]()() == 4 // this weird statement returns true
What happens here is this order of evaluation:
"hi".length
is evaluated to 2
2 == 2
is evaluated to true
obj[true]
, after true
is coerced to a string, is evaluated to "stuff"
window["stuff"]
is evaluated to an existent function2+2
and returns 4
4 == 4
is evaluated to true
Upvotes: 2
Reputation: 48367
What is happening here?
Firstly, it's evaluating the right expression LAUNCH === 'ready'
which is true
.
Then, just assign this value to isReady
variable. isReady
variable will hold everytime one boolean
value.
Upvotes: 3