Javascript has two sets of equality operators, one is == and !=, and the other is === and !==. The former only compares the equality of values, while the latter compares whether the types are the same in addition to values.
Please try not to use the former group, always only use === and !==. Because == performs type conversion by default, the rules are very difficult to remember. If you don't believe it, please answer whether the value of the following five judgments is true or false:
false == 'false'
false == undefined
false == null
null == undefined
0 == ''
The first three are false and the last two are true.
2.with
The original intention of with is to reduce keyboard input. For example,
obj.a = obj.b;
obj.c = obj.d;
can be abbreviated as
with(obj) {
a = b;
c = d;
}
But , during actual operation, the interpreter will first determine whether obj.b and obj.d exist. If they do not exist, then determine whether the global variables b and d exist. This leads to inefficiency and may lead to accidents, so it is best not to use the with statement.
3.eval
eval is used to directly execute a string. This statement should also not be used as it has performance and security issues and makes the code harder to read.
What eval can do, you can do without it. For example
eval("myValue = myObject." myKey ";");
can be written directly as
myValue = myObject[myKey];
As for the json string returned by the ajax operation, you can use the official website The parser provided by json_parse.js is run.
4.continue
The function of this command is to return to the head of the loop, but the loop will return to the head. Therefore, through proper construction, the use of this command can be completely avoided, improving efficiency.
5.switch The case statements in the
switch structure are executed sequentially by default, unless break, return and throw are encountered. Some programmers like to take advantage of this feature, such as
switch( n) {
case 1:
case 2:
break;
}
Writing like this is error-prone and difficult to find. Therefore, it is recommended to avoid switch penetration and add break wherever there is a case.
switch(n) {
case 1:
break;
case 2:
break;
}
6. Single-line block structure
if, while, do and for are all block structure statements, but they can also accept single-line commands. For example,
if (ok) t = true;
is even written as
if (ok)
t = true;
This is not conducive to reading the code, and it is very easy to make mistakes when adding statements in the future. It is recommended that curly brackets be added regardless of whether there is only one line of command.
if (ok){
t = true;
}
7. And --
increment operator and decrement operator--, directly Coming from the C language, it can make the code very compact on the surface, but in fact it makes the code look more complex and obscure. Therefore, for the sake of cleanliness and readability of the code, it is better not to use it.
8. Bitwise Operators
Javascript fully applies Java’s bitwise operators, including bitwise AND&, bitwise OR|, bitwise XOR^, and bitwise NOT. ~, left shift >, and zero-padded right shift>>>.
This set of operators is for integers, so it is completely useless for Javascript, because inside Javascript, all numbers are saved as double-precision floating point numbers. If they are used, Javascript has to convert the operands to integers first and then perform the operation, which slows down the speed. Moreover, the "bitwise AND operator" & is the same as the "logical AND operator" &&, which is easy to confuse.
9. function statement
Define a function in Javascript. There are two ways to write it:
Function foo() { }
and
var foo = function () { }
The two writing methods are completely equivalent. However, during parsing, the former way of writing will be automatically promoted to the head of the code by the parser, thus violating the requirement that functions should be defined first and then used. Therefore, it is recommended to use the latter way of writing when defining functions.
10. Packaging objects of basic data types
The basic data types of Javascript include strings, numbers, and Boolean values, and they all have corresponding packaging objects String, Number, and Boolean. So, someone would define the relevant value like this:
new String( "Hello World");
new Number(2000);
new Boolean(false);
Writing like this is completely unnecessary and very confusing, so it is recommended not to use it.
In addition, the use of new Object and new Array is not recommended and can be replaced by {} and [].
11.new statement
Javascript is the first widely used language in the world to support Lambda functions. It is essentially a functional programming language similar to Lisp. But in the current world, more than 90% of programmers use object-oriented programming. In order to get closer to the mainstream, Javascript made a compromise and adopted the concept of classes, allowing objects to be generated based on classes. The
class is defined like this:
var Cat = function (name) {
this.name = name; new Cat('mimi');
This syntax of using functions to generate classes and new to generate objects is actually very strange and not intuitive at all. Moreover, when using it, it is easy to forget to add new, and it will become an execution function, and then there will be several more global variables inexplicably. Therefore, it is recommended not to create objects this way, but to use a workaround.
Douglas Crockford gave a function:
Copy code
Use this function when creating an object to operate on the prototype object:
After the object is generated, you can assign related attributes by yourself:
myCat.name = 'mimi';
12.void
In most languages, void is A type that represents no value. But in Javascript, void is an operator that accepts an operand and returns undefined.
void 0; // undefined
This command is useless and confusing. It is recommended to avoid using it.

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor
