#JavaScript : The Things from the Video by Douglas Crockford – Part 1

I was listening to the Video “The JavaScript Programming Language” (1/4) by Douglas Crockford. Thought I would share few things that I’ve learned from this video which I didn’t know (or may be I forgot?). Presentation Slides are Here.

1. Type Coercion in Equal and not Equal
==, !== and ===, !===

[javascript]
2==2
//true

2=="2"
//true

2===2
//true

2==="2"
//false
[/javascript]

It's been advised to use === and !== instead of == and !== for optimization and reliability. Hence, it avoids type coercion (typecasting).

2. bang bang (!!)

[javascript]
!!2
//true

!!0
//false

!!""
//false
[/javascript]

**This is equal to Boolean() function

3. Unary Operator +
[javascript]
+"365"
//365
[/javascript]

** Here '+' operator performs same thing as Number() function
4. Logical Operators - && and || are just like and & or operator in Python.
[javascript]
4 && 5 && 0 && 7
//0 - first faulty operand

0 || "" || 9 || 6
//9 - first truthy operand
[/javascript]

will post the interesting things from the rest of his Videos. Ciao!

Posted on Jul 16, 2010
Written byAbhinay Omkar
  • Anonymous

    That’s awesome! Thanks! 🙂

  • Its a very useful information.Keep on posting such information soon your bloge will have a better rank

  • A very good and a interesting blog.
    Thanks for sharing.