7. BEST PRACTICES
AVOID GLOBAL VARIABLES
<script>
var now = new Date();
/* more code goes here */
function doSomething(){
alert('the time is ' + now);
}
</script>
/* code below can overwrite "now" var */
<script src="js/dateLibrary.js"></script>
8. PROTECT YOUR VARIABLES WITH SCOPE
<script>
(function(){ // closure function
var now = new Date();
/* more code goes here */
function doSomething(){
alert('the time is ' + now);
}
})();
</script>
/* code below CAN'T change "now" var */
9.
10. WHY DO PEOPLE HATE
DEBUGGING JS?
VARIABLES ARE GLOBAL IN SCOPE
NO REQUIRED STRONG TYPING
CROSS BROWSER COMPATIBILITY (IE!!!)
NO CLASSES
13. BREAKPOINTS
Continue: continues code execution until we encounter
another breakpoint
Step Over: step through code line-by-line to get insights into
how each line affects the variables being updated. Should
your code call another function, the debugger won't jump into its
code, instead stepping over so that the focus remains on the
current function (scope).
Step Into: like Step over, however clicking Step into at the
function call will cause the debugger to move its execution
to the first line in the functions definition.
Step Out: having stepped into a function, clicking this will
cause the remainder of the function definition to be run and
the debugger will move its execution to the parent function
16. ADDING A WATCH: MULTIPLE WAYS
k Sources: select then right-click
k Click "+" on Watch Expressions panel
k Right-click inside Watch Expressions panel
32. RESOURCES / QUESTIONS?
Chrome Dev Tools:
https://developer.chrome.com/devtools
Chrome Dev Tools: Tips & Tricks
https://developer.chrome.com/devtools/docs/tips-and-tricks
jQuery Learning Center:
http://learn.jquery.com/javascript-101/
Design Patterns:
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
Douglas Crockford: Javascript the Good Parts
http://javascript.crockford.com/