Before writing more complex code, let’s talk about debugging.… Debugging is the process of finding and fixing errors within a script.… All modern browsers and most other environments support debugging tools – a special UI in developer tools… that makes debugging much easier.… The JavaScript Debugging pane is for debugging, we’ll explore it soon.
We’ll come back to developer tools later and cover debugging more in-depth in the chapter Debugging in
important side effect in V8 (Chrome, Edge, Opera) is that such variable will become unavailable in debugging… That may lead to funny (if not such time-consuming) debugging issues.… If you are debugging with Chrome/Edge/Opera, sooner or later you will meet it.… That is not a bug in the debugger, but rather a special feature of V8.
So that’s a bug!
Here the consequences are not terrible.… That makes such bugs hard to notice and even turn them into vulnerabilities, especially when JavaScript
Used for debugging purposes.… Even in open-source utilities used by millions for decades – suddenly a bug may be discovered that leads… That’s wrong and also makes the code more difficult to debug.
We can go further and make a convenience function for current debug logs:
The value type is easy to find out by debugging. But what’s the meaning of the variable?… who wants to work with elem in the second half of the function will be surprised… Only during the debugging
document.documentElement.scrollLeft/scrollTop works in most browsers, except older WebKit-based ones, like Safari (bug
, coding errors can be silenced where not appropriate, and become more difficult to debug.
It works in all browsers except Firefox (bug
Also it is possible to stringify the whole storage object, e.g. for debugging
The great thing about them is that style-checking can also find some bugs, like typos in variable or
Upon creation, we can give symbols a description (also called a symbol name), mostly useful for debugging
Here are typical mistakes in hand-written JSON (sometimes we have to write it for debugging purposes)
For requests to our origin we still get the full Referer (maybe useful for debugging purposes).
Such programmers save a little bit on variable declaration but lose ten times more on debugging.
string conversions that should return a “human-readable” representation of an object, for logging or debugging
and explore “in-place”, like document.body below:
That’s for debugging
A separate function is not only easier to test and debug – its very existence is a great comment!
And then our users meet bugs, as we probably fail to check something manually.
provides better insight into the language and also explains the behavior that might be a source of bugs
base=2 is mostly for debugging bitwise operations, digits can be 0 or 1.
be possible at all, hackers should not be able to inject their code into our site, but there may be bugs