Friday, September 12, 2014

5 things you probably didn't know about Javascript

I have been working with JavaScript since maybe 1997 in some capacity.  Like most people it was something that you used used to solve a task and move on without any formal training so the fundamentals of the language escape most people who develop it.  Over the years JavaScript as been an increasingly powerful language with more and more processing being done client side.  I dream of one day having a job where my focus is on JavaScript so I have a reason to invest in developing an in depth understanding of the language.  Here is a list of five things that I recently learned about JavaScript that blew my mind even after over nearly 20 years coding it.

  1. JavaScript has a spec! BOOKMARK IT ASAP
  2. Really JavaScript isn't wild and free like the cowboys of yesteryear. Of course it had to be defined in a spec somewhere but have you ever seen it or even considering looking for it?
  3. JavaScript, I am not joking, has a spec and it is readable and user friendly.  If you do not understand something the spec seems to have a well laid out definition for everything.
  4. JavaScript has a spec that very well defined.  It isn't wild and free and depending on the browsers playing nice with it.
  5. JavaScript is versioned; the spec is available for past versions and versions that are not support yet.. 

Other candidates that did not make the list
  • JavaScript is a compiled language.  
    • I always thought it was up to the browsers to interpret it at run time.
    • Understand how the compiler and engine work in order to rule the world. mwhahaha
  • JavaScript can be run server side
    • What do you mean there are uses for JavaScript beyond client side the web browser!?!
  • The way the code work is enough to blow your mind
    • Example: 
      • Why does it go in the if block if it is false?
        if ('true') {
            'true' == true  // returns false
            'true' == false // returns false
      • Answer: In the if check 'true' is coerced into being a boolean using ToBoolean (check the spec) which equates any of the following values to be 'falsey' if not they will result in a true boolean value.
        • empty string ("") (does not even include whitespace)
        • false
        • 0
        • NaN
        • undefined
        • null
  • Edit any web (you cannot publish it back to the server) by executing the following line of code in your web console.  This is not so much something crazy you didn't know but a cheesy parlor trick to amuse your friends.  It is easy to remember to at least temporarily make your new intern in awe of you.
    • document.designMode='on';

No comments:

Post a Comment