Skip navigation

Tag Archives: shock

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

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

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

(function( window, undefined ) {

})( window );
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.

JavaScript have some odd behaviour on object property names. If you know this for first time, you will be shocked. Programmers from other language background will be surprised to know this kind of JavaScript behaviour.

// declare a variable and create a new object with property name and value raja

var myO = {name:"raja"};
alert(;  //raja

Your shocks starts here…

myO.if = "use reserved word";
alert(myO.if);  //use of reserved word

myO["if else if && || *^ "] = "you can use anything";
alert(myO["if else if && || *^ "]);  //you can use anything

myO[""] = "Surprise";  // no error. even empty is allowed
alert(myO[""]);  // Surprise

Similar article written by mathias

You can comment in two ways in JavaScript code.

1) First one is to comment single line. For that we use two front slashes like //. Then the entire line will be considered as comment


// This is a comment in JavaScript code

2) Second one is to comment multiple lines. For that we use start with /* and end with */

/* This is the multi line
comment is JavaScript code */

So, where is the shock???

When you are using regular expression, be careful because you may encounter error.

var reg = /a*/.match(str);

So even when using comments, you should be careful…

Hope this will help…