Debugging Javascript
1. Use Firebug -
a. There is a console output where in you can type statements like 2*3 and press ENTER.
i. "\u03c0" press ENTER and see what comes.
b. Console.log("what ever you want to dump in console") frees you from alert.
c. Once you get a error in console window then restarting firefox helps
2. FireFox - Tools - Error console
a. Repeat 1 a above and click on evaluate.
b. "\xA9" press ENTER and see what comes.
3. Browser window location bar
a. The place where you type http://dsteps.blogspot.com instead try
i. Javascript:10%2 and press ENTER.
ii. javascript:for
Other notable facts
1. Functions are values that can be manipulated like datatypes. Thus they can store in variables, arrays and objects and can pass around as parameters too.
a. var sq = function(x){return x*x};
b. function sq(x){return x*x;}
c. Pont a and b are same.
2. If you don’t initialize a var variable then its value is undefined.
3. If you don’t use var then variable declaration is global even though it may be in function body and may conflict with a global name.
4. Variable declarations are not restricted by block. Say a variable in loop will be visible outside the loop too and is defined for the entire function body. Effectively hiding or masking the global variable with same name. Initialization can happen anywhere in function body with another var declaration and assignment.
5. Reading value of an undeclared variable will cause runtime error as they are undefined. Assigning value to undeclared variable is done by implicit declaration in global scope.
1. Use Firebug -
a. There is a console output where in you can type statements like 2*3 and press ENTER.
i. "\u03c0" press ENTER and see what comes.
b. Console.log("what ever you want to dump in console") frees you from alert.
c. Once you get a error in console window then restarting firefox helps
2. FireFox - Tools - Error console
a. Repeat 1 a above and click on evaluate.
b. "\xA9" press ENTER and see what comes.
3. Browser window location bar
a. The place where you type http://dsteps.blogspot.com instead try
i. Javascript:10%2 and press ENTER.
ii. javascript:for
(i=0,j=1,fib=j;fib<100;i=j,j=fib,fib=i+j){document.write(i+"+"+j+"="+fib+"
");}
Other notable facts
1. Functions are values that can be manipulated like datatypes. Thus they can store in variables, arrays and objects and can pass around as parameters too.
a. var sq = function(x){return x*x};
b. function sq(x){return x*x;}
c. Pont a and b are same.
2. If you don’t initialize a var variable then its value is undefined.
3. If you don’t use var then variable declaration is global even though it may be in function body and may conflict with a global name.
4. Variable declarations are not restricted by block. Say a variable in loop will be visible outside the loop too and is defined for the entire function body. Effectively hiding or masking the global variable with same name. Initialization can happen anywhere in function body with another var declaration and assignment.
5. Reading value of an undeclared variable will cause runtime error as they are undefined. Assigning value to undeclared variable is done by implicit declaration in global scope.
Comments