Đoạn code javascript sau có xảy ra lỗi không? Hãy giải thích tại sao?
Đoạn code javascript sau có xảy ra lỗi không? Hãy giải thích tại sao?
function greeting() {
throw "Hello world!";
}
function sayHi() {
try {
const data = greeting();
console.log("It worked!", data);
} catch (e) {
console.log("Oh no an error!", e);
}
}
sayHi();
"It worked! Hello world!""Oh no an error: undefinedSyntaxError: can only throw Error objects"Oh no an error: Hello world!Với lệnh throw, chúng ta có thể tạo ra c...
middle