Learning Javascript Programming Language Part 2


Intent of my Blog

This blog is a second in the series of my learning javascript programming language. In the first blog i discussed and shared the history of the javascript programming language. For learning javascript, i am following Douglas Crockford videos on YUI theater and book “JavaScript: The Definitive Guide 4th Edition”. In this blog, i will share some of the things that i learned about the language.

Get Started

Today i have seen the second lecture of the series. Checkout this lecture

Key Points from the Presentation are :
  1. The statements in javascript are separated from each other with semicolon. If you place each statement on the separate line, javascript allows you to leave the semicolon.But it is a good idea to put semicolon.
  2. Expression statements are expressions which have a side-effect.
  3. Statements discussed are :- if, switch, while, for, throw, try/catch/finally, function, var, return
  4. If statements is the control statement that allows JavaScript to make decisions,or to execute statements conditionally.
  5. If statement is written like this  if(expression) statement
  6. if the expression is null, undefined, 0,”” or NaN it is converted to false.
  7. Switch statement in JavaScript are different from switch statement in C,C++ or java. In those languages, the case expression must be compile time constant.They must evaluate to integer or other integral types and they must evaluate to same type.
  8. JavaScript switch statement is not nearly as efficient as the switch statement in C, C++, and Java. Since the case expressions in those languages are compile-time constants, they never need to be evaluated at runtime as they are in JavaScript. Furthermore, since the case expressions are integral values in C, C++, and Java, the switch statement can often be implemented using a highly efficient “jump table.”
  9. There is a special version of for loop which exists for objects
    for(var name in object){
    of(object.hasOwnProperty(name)){
    // do something
    }
    }
    
  10. In the var statement, if no initial value is specified for a variable, the value of the variable is undefined
  11. throw statement can throw error or any subclass of error
  12. throw can also be useful to throw a string that contains an error message, or a numeric value that represents some sort of error code.
  13. Do not use with statement because the code that uses with is difficult to optimize.
  14. The try/catch/finally statement is JavaScript’s exception-handling mechanism. The try clause of this statement simply defines the block of code whose exceptions are to be handled. The try block is followed by a catch clause, which is a block of statements that are invoked when an exception occurs anywhere within the try block. The catch clause is followed by a finally block containing cleanup code that is guaranteed to be executed, regardless of what happens in the try block. Both the catch and finally blocks are optional, but a try block must be accompanied by at least one of these blocks.
  15. Every function will have a return statement, sometimes return will return some value and sometime it will be return without any expression.
These were some the important points from the talk. I have not covered functions and objects in this blog. I will share those in future posts.

2 thoughts on “Learning Javascript Programming Language Part 2

  1. Pingback: Learning JavaScript Programming Language Functions Part 3 « My Thoughts on software development

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s