Javascript - Debug Javascript - Part 1 - Introduction to general debugging concepts
Ağustos 5, 2012 by Javascript Tutorial
|
|
his Javascript tutorial contains and tries to cover following subjects:
- Introduction to Javascript debugging
- General debugging concepts which applies debuggers
Articles tries to provide answer to following questions and issues:
- How to handle errors in Javascript
- How to debug in javascript?
- How to use a Javascript debugger to find errors?
Articles pre-requisites following information:
- General knowledge of variables in Javascript
- General knowledge of functions
- General knowledge of HTML
Explanation of Javascript try catch
In this Javascript Tutorial, we will cover Javascript debugging subject briefly to understand what is debugging, where and why to need debugging javascript code. After got familiar with debugging general concepts, we will download a debugger to debug a code of HTML which is javascript.
What is debugging?
Like any other languages, errors can happen. Error source can be due to the programmer or an unexpected application behavior in run-time. For instance, assume that we accept user inputs to put data into database. User name is string and age is numeric. However use tried to write a string into age which is denied by database. And the function in our code was accepting parameter number to pass data into database. In .NET it will cause run-time error. Cases can be various. To understand a error, debugging is a process.
In debugging, basically a break-point is added to code. This means, when code is executed, instead code to be executed till end, execution is resumed in that breakpoint. Breakpoint can be the place, where before a suspected variable that we believe does not get the value we expect. Idea behind here is to tell compiler resume in a place to let use see what kind of variables or functions are executed. In debugging process, we can see what a function has returned, which functions are executed, values of objects and custom watch or monitoring can be performed while application is runing.
Javascript debugging process is similar like other languages. Therefore, lets look into general concepts first. What are main things of a debugging process:
breakpoint: a mark which is put to the code to tell compiler resume execution in that line
Watches: watches are specified for variables that are being monitored during execution
Call stack: call stack is some sort of box that keeps records of functions which are executed till breakpoint
Console: allows programmer to execute commands in run-time - in HTML page.
Stepping: Stepping is main subject in debugging. While we debug a code, we execute a javascript code one line per execution. Stepping here means, every line we execute is a step. Similar to go step-by-step. Stepping has 3 part.
1. Step into: Executes a line (next line) of code. If next is function, executes function. Halts at the first line of function (inside the function)
2. Step over: Executes a line (next line). If execution is in function, executes all lines of function till it finishes and comes to first line following following the function. (the first line after function)
3. Step out: Returns to the function which called function that we are in. We will look into this detailed in javascript example to understand better.
In following part of that javascript tutorial, we will cover stepping more detailed from "step into" to "step out" with a HTML example.
Data Layers
Area: | programming \ languages \ javascript \ \ \ |
Ref: | |
Loc: | articles |
Tags: | javascript |
|