Some tips on how to easily cause bugs in JavaScript programming
This article mainly introduces some tips that are prone to bugs in JavaScript programming. This article summarizes 8 tips. If you don’t understand these tips, they will cause you trouble and bugs in programming. You need Friends can refer to
JavaScript is one of the most popular programming languages today, but its popularity is also a side effect of the various features of the language itself. No matter how beautiful the language is, there are still thousands of people using it every day Tens of thousands of programmers created a bunch of bugs. Don't laugh at others yet, maybe you are one of them.
To give you an example, here are a few short JS snippets that are completely valid (you can try it out on your console):
typeof NaN === 'number' // true Infinity === 1/0 // true 0.1 + 0.2 === 0.3 // false,前面加括号也一样 "3" + 1 // '31' "3" - 1 // 2
Do you still believe it? Your own JavaScript?
1. The smallest value in JS
Number.MIN_VALUE > 0; //true
Number.MIN_VALUE is used for the smallest value that JavaScript can express, which is 5e-324, but it is the closest in JS A number of 0
2. String connection
("foo" + + "bar") === "fooNaN" //true "why I am " + typeof + "" // why I am number
JS is parsed into "foo" ("bar"), which will convert "bar" into a number
3. parseInt function
parseInt('06'); // 6 parseInt('08'); // 0 注意,谷歌新版已修正 parseInt(null, 24) === 23 // true
4. Is null an object
typeof null // object null instanceof Object // false
5. The content returned by return
function myjson() { return [ 2 ] } myjson(); // undefined
The content returned by return must be on the same line as return
6. Strange numbers
012 == 12 // false '012' == 12 // true "3" + 1 // '31' "3" - 1 // 2 0.1 + 0.2 == 0.3 // false 0.1 + 0.7 == 0.8 // false 0.2 + 0.7 == 0.9 // false 9999999999999999 // 10000000000000000 9999999999999999-1 //10000000000000000 111111111111111111111 // 111111111111111110000
7. Weird parameters
function hello(what) { alert(arguments[0]); //vicky what = "world"; return "Hello, " + arguments[0] + "!"; } hello("vicky"); //"Hello, world!"
8. The head-scratching equal sign
NaN === NaN; // false [] == false; // true "" == false; // true null == false; // false [] == ![] // true window.window == window // true window.window === window // false,有些浏览器是true window == document // true,有些浏览器是false ("0" && {}) == 0 // false (0 && {}) == 0 // true 0 == "0" // true [] == 0 // true
That’s it For the entire content of this chapter, please visit JavaScript Video Tutorial for more related tutorials!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to remove duplicate values from PHP array using regular expressions: Use regular expression /(.*)(.+)/i to match and replace duplicates. Iterate through the array elements and check for matches using preg_match. If it matches, skip the value; otherwise, add it to a new array with no duplicate values.

As Apple's WWDC conference 2024 came to a successful conclusion, not only macos15 was announced, but the update of Apple's new iOS18 system attracted the most attention. Although there are many new features, as the first version of Apple's iOS18, people inevitably wonder whether it is necessary to upgrade Apple. iOS18, what kind of bugs are there in the latest release of Apple iOS18? After real use evaluation, the following is a summary of Apple iOS18 bugs, let’s take a look. Currently, many iPhone users are rushing to upgrade to iOS18. However, various system bugs are making people uncomfortable. Some bloggers said that you should be cautious when upgrading to iOS18 because "there are so many bugs." The blogger said that if your iPhone is

1. Programming can be used to develop various software and applications, including websites, mobile applications, games, and data analysis tools. Its application fields are very wide, covering almost all industries, including scientific research, health care, finance, education, entertainment, etc. 2. Learning programming can help us improve our problem-solving skills and logical thinking skills. During programming, we need to analyze and understand problems, find solutions, and translate them into code. This way of thinking can cultivate our analytical and abstract abilities and improve our ability to solve practical problems.

Build browser-based applications with Golang Golang combines with JavaScript to build dynamic front-end experiences. Install Golang: Visit https://golang.org/doc/install. Set up a Golang project: Create a file called main.go. Using GorillaWebToolkit: Add GorillaWebToolkit code to handle HTTP requests. Create HTML template: Create index.html in the templates subdirectory, which is the main template.

C++ programming puzzles cover algorithm and data structure concepts such as Fibonacci sequence, factorial, Hamming distance, maximum and minimum values of arrays, etc. By solving these puzzles, you can consolidate C++ knowledge and improve algorithm understanding and programming skills.

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

C is an ideal choice for beginners to learn system programming. It contains the following components: header files, functions and main functions. A simple C program that can print "HelloWorld" needs a header file containing the standard input/output function declaration and uses the printf function in the main function to print. C programs can be compiled and run by using the GCC compiler. After you master the basics, you can move on to topics such as data types, functions, arrays, and file handling to become a proficient C programmer.
