CARVIEW |
Debugging basics and error handling JavaScript
Debugging basics and error handling Javascript
Question 1
Which of the following is the correct way to log a variable in JavaScript?
debug(x);
console.print(x);
log(x);
console.log(x);
Question 2
What kind of error is this?
console.log("Hello);
Runtime Error
Syntax Error
Logical Error
Reference Error
Question 3
What will the following code log?
let x = 0;
if (x = 10) {
console.log("x is 10");
}
SyntaxError
"x is 10"
Nothing
ReferenceError
Question 4
What will the following code output?
let name;
console.log(name.length);
undefined
0
TypeError
NaN
Question 5
What is the output of this code?
try {
throw new Error("Something went wrong");
} catch (e) {
console.log(e.message);
}
Error
false
undefined
Something went wrong
Question 6
What does the finally block do in a try-catch-finally structure?
Always runs
Runs only if catch executes
Only runs if there's an error
Only runs if no error occurs
Question 7
Which is a common mistake with switch-case statements in JS?
Using var inside case
Forgetting default
Using == instead of ===
Using numbers in cases
Question 8
How can you avoid floating point precision errors in JavaScript?
Round every result
Multiply and divide integers
Use BigInt
Avoid using decimals
Question 9
What is wrong with the following code?
let obj = {};
if (obj === null && typeof obj !== "undefined") {
console.log("Valid");
}
Nothing
obj is null
Order of conditions is incorrect
obj is undefined
Question 10
What is the output?
try {
console.log("try");
} catch (e) {
console.log("catch");
} finally {
console.log("finally");
}
try
try finally
catch
finally only
There are 10 questions to complete.