javascript funkyness

Posted on August 22nd, 2010 by thiswayup.
Categories: dev.

As I've started to learn more about javascript this year , I've been really enjoy digesting some interesting resources on the internet to learn more about the innards that make this rather great lanaguage. One that I have found is a great google tech talk "JavaScript: The Good Parts" from Doug Crockford and he highlighted a rather quiky thing in javascript.

function good(){
   return true
}
alert( good() );
//alert is true

function bad(){
   return
   true
}
alert( bad() );
//alert is "undefined";

One would think that if you run both function you would get the same return (ie true) but there's one thing I learnt from Doug's talk is that Javascript was built with a interesting quirk, if it runs into a compilation error, it actually backs up and puts in a semi colon in for you! This was originally designed to help people first picking up the language but as a consequence has caused this weird business. So the moral is to always add semi colons.

2 comments.

Dave Knapik

Comment on August 22nd, 2010.

Interesting! I never knew that. I'm rather obsessive-compulsive about my semicolons, however, so now I'm justified! :)

thiswayup

Comment on August 22nd, 2010.

yip! That video also highlights some other cool stuff about javascript.

I reckon javascript will get big again with google and the fact are start to use more server side javascript!

Leave a comment

Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.




roma escort . where to find milf moms cooney I was very pleased