0
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?

noob
  • 101
  • 6
  • 2
    It doesn't set `x` to anything; it returns a `true` or `false` depending on the state of `x`. `x` will not be altered by this statement –  Apr 17 '14 at 09:10
  • 1
    You're missing part of this statement because what you have so far doesn't have an assignment or a logic directive. As you're shown it, that line by itself does nothing. It creates a value `true` or `false` that can be used in an assignment or logic statement (which you don't show). – jfriend00 Apr 17 '14 at 09:11
  • See `http://en.wikipedia.org/wiki/%3F:` – elclanrs Apr 17 '14 at 09:13
  • This is a ternary operator, consider it a shorthand if/else. [See here](http://msdn.microsoft.com/en-us/library/ie/be21c7hw%28v=vs.94%29.aspx) – Ian Brindley Apr 17 '14 at 09:14
  • 1
    @FrédéricHamidi - not quite because it's `===` so if `x` was `null` or any falsey value besides `false`, you'd get a different answer. – jfriend00 Apr 17 '14 at 09:15
  • @jfriend00, ah, you're right, it isn't always equivalent. My bad. – Frédéric Hamidi Apr 17 '14 at 09:16

3 Answers3

3

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

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
  • 1
    @noob: See http://stackoverflow.com/a/359509/61470 for a good explanation on strict equality and it's more relaxed counter part. –  Apr 17 '14 at 09:14
1
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;
}
Dean Meehan
  • 2,511
  • 22
  • 36
0

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

or in long hand

 if (x === false)
 {
   return true;
 }
 else 
 {
    return false;
 }
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125