Debugging ng JavaScript
- Previous Page JS JSON
- Next Page JS Style Guide
Ang mga error ay magaganap, bawat beses na isinusulat ng bagong kompyuter code.
Debugging ng JavaScript
Ang pagpagsulat ng JavaScript ng walang debugger ay mahirap.
Maaaring mayroon sa iyong code ang mga error sa grammar o logic, na mahirap na pagdiagnose.
Kadalasan, kung ang JavaScript code ay mayroong error, walang mangyayari. Walang mensahe ng error at walang kahulugan na makakita ng error.
Kadalasan, bawat beses na sinusubukang isulat ng bagong JavaScript code, maaring magkaroon ng error.
JavaScript debugger
Ang paghahanap ng mga error sa coding ay tinatawag na debugging ng code.
Ang debugging ay hindi madali. Subalit saayos, lahat ng modernong browser ay may built-in na debugger.
Ang mga built-in na debugger ay maaaring buksan o isara, at sapilitan ang pag-uulat ng error sa user.
Sa pamamagitan ng debugger, maari mo ring itayo ng tuldok (ang lugar kung saan ang code ay napagtagal), at makapag-check ng variable habang ang code ay nagpapatuloy.
Kadalasan, sa pamamagitan ng F12 key, maaring magsimula ang debugger ng browser, at pagkatapos ay pumili sa menu ng debugger ang "Console".
console.log() method
Kung ang iyong browser ay sumusuporta sa debugging, maari kang gumamit ng console.log()
Ipakita ang halaga ng JavaScript sa debugging window:
实例
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <script> a = 5; b = 6; c = a + b; console.log(c); </script> </body> </html>
Mga tagubilin:Pumunta sa aming JavaScript Console Reference Manual upang makakuha ng higit pang impormasyon tungkol sa console.log() method.
Tayo ng tuldok
Sa debugging window, maari kang itayo ng tuldok sa JavaScript code.
Sa bawat tuldok, ang JavaScript ay magtitigil ng pagpapatuloy upang ikaw ay makapag-check ng halaga ng JavaScript.
Pagkatapos ng pag-check ng halaga, maari kang ituloy ang pagpapatuloy ng code.
debugger keyword
debugger Ang mga keyword ay magtitigil ng pagpapatuloy ng JavaScript at magsagawa ng (kung mayroon) debugging function.
Ito ay katulad ng pagtayo ng tuldok sa debugger.
Kung ang debugger ay hindi magagamit,debugger
Ang statement na ito ay walang epekto.
Kung ang debugger ay bukas, ang code na ito ay magtitigil sa pagpapatuloy bago dumating ang pangalawang linya.
实例
var x = 15 * 5; debugger; document.getElementById("demo").innerHTML = x;
Debugging Tools of Mainstream Browsers
Generally, you can enable debugging by pressing F12 in the browser and selecting 'Console' from the debugger menu.
If not, please follow the following steps:
Chrome
- Open the browser
- From Menu, select Tools
- From Tools, select Developer Tools
- Finally, select Console
Firefox Firebug
- Open the browser
- Go to the website: http://www.getfirebug.com
- According to the following instructions: How to install Firebug
Internet Explorer
- Open the browser
- From Menu, select Tools
- From Tools, select Developer Tools
- Finally, select Console
Opera
- Open the browser
- Please visit the website: http://dev.opera.com
- According to the following instructions: How to install Firebug Lite
Safari Develop Menu
- Click Safari Menu, Preferences, Advanced
- Check 'Enable Developer Menu in Menu Bar'
- When a new option 'Developer' appears in the menu, select 'Show Error Console'
Did you know?
Debugging is the process of testing, finding, and reducing bugs (errors) in computer programs.
The first known computer bug was a real insect (a bug) that got stuck in an electronic device.
- Previous Page JS JSON
- Next Page JS Style Guide