Question: Having the following test case: (find fiddle [**here**](https://jsfiddle.net/5qct25hu/))

```
var a = new Date();
var b = null;
var c = {test: "test"};

if(a)
    console.log(a); //--- prints the current date

if(b)
    console.log('null'); //--- never reached

if(c)
    console.log('test'); //--- prints 'test'

console.log(a && b); //--- prints null

```

Knowing that 

```
console.log(typeof null); //--- prints "object"
console.log(typeof c); //--- prints "object"

```

I expect the result of

```
console.log(a && b); 

```

to be **false** and not **null** as it shown in the example.

Any hint?

Answer: 
> 
> I expect the result of
> 
> 
> 
> ```
> console.log(a && b);
> 
> ```
> 
> to be `false` and not `null` as it shown in the example.
> 
> 
> 

In many languages with `&&` and `||` operators (or `AND` and `OR`), the result is always a boolean, yes.\* But JavaScript's `&&` and `||` are more useful than that: Their result is their left-hand operand's value or their right-hand operand's value, **not** coerced to boolean.

Here's how `&&` works:

1. Evaluate the left-hand operand.
2. If the value is *falsey* (coerces to `false` when we make it a boolean), return the value (not the coerced value)
3. If the value from #2 is *truthy*, evaluate and return the right-hand value (uncoerced)

The *falsey* values are `null`, `undefined`, `0`, `""`, `NaN`, and of course, `false`. Everything else is *truthy*.

So for instance

```
console.log(0 && 'hi');    // 0

```

...shows `0` because `0` is falsey. Note it resulted in `0`, not `false`. Similarly, the result here:

```
console.log(1 && 'hello'); // hello

```

...is `'hello'` because the right-hand side isn't coerced at all by `&&`.

`||` works similarly (I call it the [*curiously-powerful OR operator*](http://blog.niftysnippets.org/2008/02/javascripts-curiously-powerful-or.html)): It evaluates the left-hand side and, if that's *truthy*, takes that as its result; otherwise it evaluates the right-hand side and takes *that* as its result.

The only time you get `true` or `false` from `&&` or `||` is if the selected operand is *already* a boolean.

---

\* Of course, many (but not all) of those languages (Java, C#) also require that the operands to `&&` and `||` already be booleans. C's an exception, it does some coercion, but still has the result of the operands as a boolean (or if you go back far enough, an int that will be 1 or 0).
From MDN:

> 
> Logical AND (&&) expr1 && expr2 Returns expr1 if it can be converted
>  to false; otherwise, returns expr2. Thus, when used with Boolean
>  values, && returns true if both operands are true; otherwise, returns
>  false.
> 
> 
> 

[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators)