This article mainly introduces the console in JavaScript. introduction to The assert () function. The assert () function is an asserted tool function that is frequently used in Debugging. if you need it, refer to the development and maintenance process of JavaScript programs, assert is a good feature for ensuring program correctness. In browsers with debugging tools, this feature can be achieved by calling console. assert. For example, in the following code, the console. assert () statement ensures that the score variable length of the cat object is 3:
The code is as follows:
Function cat (name, age, score ){
This. name = name;
This. age = age;
This. score = score;
}
Var c = new cat ("miao", 2, [6, 8, 7]);
Console. assert (c. score. length = 3, "Assertion of score length failed ");
In the console. in The assert () statement, the first parameter is the result of assert, which should be true under normal conditions. The second parameter is the error message printed on the console when an error occurs. For example, if the length of the score variable array is not 3 in the preceding example:
The code is as follows:
Function cat (name, age, score ){
This. name = name;
This. age = age;
This. score = score;
}
Var c = new cat ("miao", 2, [6, 8]);
Console. assert (c. score. length = 3, "Assertion of score length failed ");
After the code is executed, the Firebug console prints the error message:
Browser support
Console. assert () provides better support for browsers with debugging tools. all major browsers support this function. However, Firefox does not support this function. you must install the Firebug plug-in on Firefox to use console. assert ().