Skip navigation

Monthly Archives: March 2012


Learning experience with JavaScript is more excited day-by-day.

//
(function(undefined) {
    alert(typeof undefined);   // boolean
})(true);
//
(function(undefined) {
    alert(typeof undefined);   // undefined
})();
//

Refer jQuery source code (development version 1.7.1) and modernizr, the first line would be

\\
\\ http://code.jquery.com/jquery-1.7.1.js 
(function( window, undefined ) {

})( window );
\\ http://www.modernizr.com/downloads/modernizr.js
window.Modernizr = (function( window, document, undefined ) {

})(this, this.document);
\\

To overcome the issue of undefined, these libraries passing undefined as local variable. Notice the third parameter is left blank.

Read my another post regarding the same topic.


In Javascript subtracting a string 5 from numeric 5 is legal and it will give you the correct result !!.

But when subtracting 5 from a string “five” it will not provide you the correct answer but javascript will not throw any error either!. In fact, it will return a value !!. The value is NaN (Not a number) and its type is number!!!.

\\
alert(5-'5');      \\ 0
alert(5-'five');   \\ NaN (no errors)
alert(typeof NaN); \\ number
\\

If a number is divided by zero, javascript returns a numeric value!!! The value is infinite. Yes it is of type number!!!

\\
alert(5/0);   \\ infinity
alert(typeof infinity); \\ number
\\

So, in javascript not only 1, 2, 3, etc., are numbers but also NaN and infinite!!

Follow

Get every new post delivered to your Inbox.

Join 150 other followers