try{
var num = pompt("请输入5~10");
}
catch(err){
console.log(err);
console.log(err + "这里我随便加上一段字符串");
}
In the above code, console.log(err);
is output on the console like this: ReferenceError: pompt is not defined at index.html:37
, there is a prompt line Number.
Butconsole.log(err "I will add a random string here");
The output in the console is like this: ReferenceError: pompt is not definedHere I will add a random string String
, if a string is added, no error line number will be prompted. What is the reason for this?
The first sentence prints an object.
The second sentence prints a string. That is, err.toString() + "I just add a string here"
Non-professional answer, for reference only-. -
You will know after logging err.toString()
Because err+str, err first calls toString to convert it into a string.
It can be like this
err is data in the form of an object, and is automatically converted into a string when connected with a plus sign.