Debugging Flashcards
example of syntax error
funtcion willNotWork( console.log("Yuck"); } // "function" keyword is misspelled and there's a missing parenthesis
example of a runtime error
function loopy() { while(true) { console.log("Hello, world!"); } } // Calling loopy starts an infinite loop, which may crash your browser
semantic error
function calcAreaOfRect(w, h) { return w + h; // This should be w * h } let myRectArea = calcAreaOfRect(2, 3); // Correct syntax and the program executes, but this gives the wrong answer
JavaScript recognizes six primitive (immutable) data types:
Boolean, Null, Undefined, Number, String, and Symbol (new with ES6) and one type for mutable items: Object.
Almost every value on its own in JavaScript evaluates to ____, except what are known as the “falsy” values:
true
false, 0, “” (an empty string), NaN, undefined, and null.
The order of arguments in the function ___
matters, and you may get incorrect output if you mix them up, type or order
Off by one errors___
crop up when you’re trying to target a specific index of a string or array (to slice or access a segment), or when looping over the indices of them.
uncover buggy behavior related to resetting, or failing to reset a variable.
Printing variable values with each cycle of your loop by using console.log()
Ways to get an infinite loop
One error is incrementing or decrementing a counter variable in the wrong direction from the terminal condition.
Another one is accidentally resetting a counter or index variable within the loop code, instead of incrementing or decrementing it.