JavaScript is a magical language, there is a magical addition operator in this magical language.
We can use commonly used addition operators to do:
1. Addition operation, for example: alert(1+2); ==>3
2. String concatenation, for example: alert("a"+"b");==>"ab"
The more advanced one is also "+=", which also does the above two operations.
Yesterday I asked a question in the javascript jungle group: How to convert the date format string "2000-09-11 19:22" into milliseconds?
Zhan Mengren answered me immediately: +new Date('2000-09-11 19:22'), I tried it but it didn't work. The correct one should be +new Date('2000/09/11 19:22').
The answer seems to be no longer important. You see, there is an add operator in front of it. To be honest, I have never seen this writing method before. The magical addition operator in javascript also has a very magical function. Converting data types is generally a conversion of strings and values. For example, the example given by javascript jungle netizen jason:
The code copy is as follows:
// Hexadecimal conversion:
+"0xFF"; // -> 255
// Get the current timestamp, equivalent to `new Date().getTime()`:
+new Date();
// Parsing strings safer than parseFloat()/parseInt()
parseInt("1,000"); // -> 1, not 1000
+”1,000″; // -> NaN, much better for testing user input
parseInt("010"); // -> 8, because of the octal literal prefix
+"010"; // -> 10, `Number()` doesn't parse octal literals
//Some simple abbreviations such as: if (someVar === null) {someVar = 0};
+null; // -> 0;
// Boolean conversion to integer
+true; // -> 1;
+false; // -> 0;
//other:
+”1e10″; // -> 100000000000
+”1e-4″; // -> 0.0001
+”-12″; // -> -12:
Of course, there is also the operation of adding a number to an empty string to convert numbers into strings, for example: alert( typeof (1+”)); // ->string;
Also, a subtraction operator that converts the string into a number is attached, for example: alert( typeof ("123"-0));//->number;
Of course, there may be some unknown usage features for adding operators. Welcome to leave a message to add it!