1/29
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
Errors
______ in the operation of programs happen due to misconceptions when solving a problem, improper use and typos of the programming language, or the inability to predict user behavior.
Programming language
It communicates just like natural language in that it has its grammar and vocabulary.
grammar and vocabulary.
Programming language communicates just like natural language in that it has its _________ and _________
grammar
The “_________” in the programming language is the syntax, a set of rules that defines the structure of the instructions.
vocabulary
the “_________” are the keywords or list of words that can be used to build instructions.
Syntax Error
Correct Message:
After leaving the mall, turn right into the second path, and drive 600 m. Wait on the spot.
Same Message with Errors: missing period
After leaving the mall, turn right into the second path, and drive 600 m. Wait on the spot
This error violates the language syntax rule, as a declarative sentence should end with a period.
Type of error: __________
Semantic Error
Correct Message:
After leaving the mall, turn right into the second path, and drive 600 m. Wait on the spot.
Same Message with Errors: pth
After leaving the mall, turn right into the second pth, and drive 600 m. Wait on the spot.
This new word is not recognizable in the vocabulary of the natural language, thus creating an error. It can also be a word that is out of context, such as using “male” instead of “mall”.
Type of error: __________
Logical Error
Correct Message:
After leaving the mall, turn right into the second path, and drive 600 m. Wait on the spot.
Same Message with Errors: logical error
After leaving the mall, turn left into the second path, and drive 600 m. Wait on the spot.
It is an error as it is not what was originally the intended direction compared to the original message. This error is not easily detectable by the compiler.
Type of error: __________
SyntaxError
iff (true) {
console.log("true");
}It appears when a code is ill-formed, just like the sample above, when typos occur, or when unmatching parenthesis or brackets. The code cannot even be executed as JavaScript cannot understand it.
logical error
This error is not easily detectable by the compiler.
ReferenceError
let positive = true;
if (negative == true) {
console.log("true");
}The semantic error above is called a___________ in JavaScript, as the compiler does not know its meaning. This error occurs when the programmer tries to access a function or a variable that does not exist.
TypeError
const someConstValue = 4;
someConstValue = 3;
console.log(someConstValue);This error occurs when a specific value is not of the expected type, such as changing the constant value or checking the length of a variable that is not a string.
RangeError
let testArray1 = Array(10);
console.log(testArray1.length);
let testArray2 = Array(-1);
console.log(testArray2.length);
This error is generated when a value is passed to a function outside its acceptable range.
Exceptions
_________
When JavaScript detects syntactic or semantic errors, it generates and throws specific objects with information about the encountered error. In syntax errors, the JavaScript engine does not allow the program to run and uses the console to show the error message.
throws
When JavaScript detects syntactic or semantic errors, it generates and ______ specific objects with information about the encountered error. In syntax errors, the JavaScript engine does not allow the program to run and uses the console to show the error message.
run-time errors, or exceptions
Other errors, however, are called ____________, or ________, which appear while the program is running. By default, thrown exceptions interrupt the program execution and show the appropriate information to appear on the console.
Exception handling, or error handling,
______________, or ____________, is done to prevent the program from stopping in such a situation.
try…catch
try {
console.log('123');
console.log('123');
} catch (error) {
console.log(error.message);
}To handle exceptions in JavaScript, the _________ statement is used. If an exception is thrown in the code block after the try keyword, the program will not interrupt completely but instead jumps to the part of the code after the catch keyword and continues from there.
finally Statement
_____________ Just like the catch block, this is also an optional block of the try statement, although at least one of them is required or a SyntaxError is thrown.
finally Statement
It can be used with or without the catch block and is always executed after the try and catch blocks, no matter what errors are thrown.
10
10
let a = 5;
try {
a = 10;
} finally {
console.log(a);
}
console.log(a); What will be the output of the code above?
Debugging
__________ is part of troubleshooting in programming.
debugger statement
The ______________ causes the program to stop or halt its execution on the line where it is placed and waits for a decision.
Before debugger
console.log("Before debugger");
debugger; console.log("After debugger");
If debugging is present in a browser, the console in the developer tool will only show the ___________ log and display whether the code execution stopped, paused in the debugger, or is currently in debug mode.
breakpoint
the debugger statement also works as a _________ in the code execution, pausing the debugger execution.
Step-by-Step Program Execution
It is a debugger feature to execute codes on a step-by-step basis. It means that program execution can be stopped at any place using the debugger statement and then continue the execution one instruction at a time.
Resume
resumes the execution of the script typically. The debugger runs the program and “breaks” on user-defined breakpoints.
Step Into
treats the function as a set of instructions intended to be executed separately. It is used when the code needs to be analyzed in detail. The debugger will jump inside the code of the next instruction if it is a function call.
Step Over
is used when the next instruction is a call to a function where the impact is unclear or uninterested. It treats the function call as something indivisible
Step Out
allows to immediately jump out of a function where the code is paused. This action proceeds until the function returns if the debugger is within the code block.