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 :
- 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.
- Expression statements are expressions which have a side-effect.
- Statements discussed are :- if, switch, while, for, throw, try/catch/finally, function, var, return
- If statements is the control statement that allows JavaScript to make decisions,or to execute statements conditionally.
- If statement is written like this if(expression) statement
- if the expression is null, undefined, 0,”” or NaN it is converted to false.
- 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.
- 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.”
- There is a special version of for loop which exists for objects
for(var name in object){ of(object.hasOwnProperty(name)){ // do something } }
- In the var statement, if no initial value is specified for a variable, the value of the variable is undefined
- throw statement can throw error or any subclass of error
- 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.
- Do not use with statement because the code that uses with is difficult to optimize.
- 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.
- 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.
very cool & good post, thank you very much for sharing.