Debugger
Tags : JavaScript Intro
Debugger
Debugger is a great tool to use when you are debugging your code. Useful to check for errors or for unexpected results.
Sometimes an error is not actually present but you are not getting the expected results. Using debugger we can actually see what the code is doing.
$(document).ready(function(){
$("form").on("submit", function(event){
event.preventDefault();
var fields = ["message", "from", "phone"];
for (var i = 0; i < fields.length; i++){
debugger;
$("."+ fields[i]).text($("input#" + fields[i]).val());
}
// fields.forEach(function(field){
// debugger
// $("."+ field).text($("input#" + field).val());
// })
})
})
Try the following:
- Use the debugger inside a for loop or inside a forEach loop.
- Use the debugger inside and if/else statement.
- Play around and see if you can access any variables or arrays you defined.