noob
noob

Reputation: 99

what does this line of javascript shorthand means?

x === false ? true: false;

what doesn't above JavaScript mean? is it if x is equal to false then set x to true or else set x to false?

Upvotes: 0

Views: 63

Answers (3)

Ghoul Fool
Ghoul Fool

Reputation: 6949

It's called the ternary operator. Learn more about it here

or in long hand

 if (x === false)
 {
   return true;
 }
 else 
 {
    return false;
 }

Upvotes: 0

Dean Meehan
Dean Meehan

Reputation: 2646

x === false ? true: false;

When x is equal and of the same type(boolean) then the statement is true else statement is false.

Written longhand would be

if(x === false){
    return true;
}else{
    return false;
}

Upvotes: 1

Evan Knowles
Evan Knowles

Reputation: 7501

That resolves to true if x is strictly equal to false, and false otherwise. No value is set for x.

Upvotes: 3

Related Questions