The console error information in js is mainly divided into two categories. The first category is syntax errors. If this type of error is encountered during the pre-parsing process, the entire js file will not be executed. Another type of error is collectively called an exception. This type of error will cause the code after the line where the error occurs to be unable to execute, but the code before that line will not be affected.
1. SyntaxError: Syntax error
// 1. Syntax Error: 语法错误 // 1.1 变量名不符合规范 var 1 // Uncaught SyntaxError: Unexpected number var 1a // Uncaught SyntaxError: Invalid or unexpected token // 1.2 给关键字赋值 function = 5 // Uncaught SyntaxError: Unexpected token =
2. Uncaught ReferenceError: Reference error
An error that occurs when referencing a variable that does not exist. Assign a value to an object that cannot be assigned, such as the result of a function or a function assignment.
// 2.1 引用了不存在的变量 a() // Uncaught ReferenceError: a is not defined console.log(b) // Uncaught ReferenceError: b is not defined // 2.2 给一个无法被赋值的对象赋值 console.log("abc") = 1 // Uncaught ReferenceError: Invalid left-hand side in assignment
3. RangeError: Range Error
RangeError is an error that occurs when a value is only outside the valid range. There are several main situations. The first is that the array length is a negative number, the second is that the method parameters of the Number object are out of range, and the function stack exceeds the maximum value.
// 3.1 数组长度为负数 [].length = -5 // Uncaught RangeError: Invalid array length // 3.2 Number对象的方法参数超出范围 var num = new Number(12.34) console.log(num.toFixed(-1)) // Uncaught RangeError: toFixed() digits argument must be between 0 and 20 at Number.toFixed // 说明: toFixed方法的作用是将数字四舍五入为指定小数位数的数字,参数是小数点后的位数,范围为0-20.
4. TypeError type error
An error that occurs when a variable or parameter is not of the expected type. For example, using new primitive types such as strings and Boolean values and calling methods that do not exist in the object will throw this error, because the parameter of the new command should be a constructor.
// 4.1 调用不存在的方法 123() // Uncaught TypeError: 123 is not a function var o = {} o.run() // Uncaught TypeError: o.run is not a function // 4.2 new关键字后接基本类型 var p = new 456 // Uncaught TypeError: 456 is not a constructor
5. URIError, URL error
The main reason is that the parameters of the related functions are incorrect.
decodeURI("%") // Uncaught URIError: URI malformed at decodeURI
Errors thrown when URI related parameters are incorrect, mainly involving six functions: encodeURI, decodeURI(), encodeURIComponent(), decodeURIComponent(), escape() and unescape().
6. EvalError eval() function execution error
In JavaScript below ES5, when the eval() function is not executed correctly, an evalError error will be thrown.
For example, the following situation:
var myEval = eval; myEval("alert('call eval')");
It should be noted that this error is no longer thrown in JavaScript above ES5, but you can still customize this type of error prompt through the new keyword .
The above 6 derived errors, together with the original Error object, are all constructors. Developers can use them to generate instances of error objects.
new Error([message[,fileName[,lineNumber]]]),
The first parameter represents the error message, the second is the file name, and the third is the line number.
Related recommendations:
Summary of common JS error types
php Detailed explanation of error types and shielding methods
Common php error types and shielding methods
The above is the detailed content of Sharing six error types in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
