• In JavaScript, all numbers are numeric regardless of integers or floating-point numbers
  • In JavaScript, NaN is a property of a global object, and its initial value is NaN. Like the special value NaN in Number, NaN means Not a Number. It can be used to indicate whether something is numeric, but it doesn’t have an exact value. Represents only one azimuth of a non-numerical type. For example, NaN is not always true when compared to NaN, because the data being manipulated can be any one of Boolean, character, null, undefined, or object types.
  • If single quotes are used within single quotes, or double quotes are used within double quotes, you need to escape them with the escape character “\”. Such as:
var say1 = 'I\'m is ... '; Output: "I'm is..." var say2 = "\"Tom\""; Output: "Tom" is to output the symbol before the \ lineCopy the code
  • The Null type has a value of Null and is used to represent a nonexistent or invalid object or address.
  • In Windows, only slashes (/) are used. And the path on the network generally use “\” to represent the path to access.
  • Undefined (undefined) has only one special undefined value, which is used when the declared variable has not been initialized. The default value of the declared variable is undefined. Unlike NULL, which means that a variable (object or address) does not exist or is invalid, undefined means that no value has been set for the variable. Note that null and undefined are not equal to empty strings (‘) and 0.

Data type detection

  • The typeof operator
var num1 = 12,num2 = '34' ,sum = 0;
console.log(typeof num1);  // Output result: number
console.log(typeof num2);  // Output: string
console.log(typeof sum);   // Output: string

console.log(typeof null);	// Output result: object instead of null
Copy the code
  • Extension functions for object prototypes
var data = null;
var type = 'Null';

Object.prototype.toString.call(data) == '[object'+type+'] ';
Copy the code

Conversion of data types

  • Boolean() converts any non-empty strings and non-zero values to true, and converts empty strings (‘ empty ‘), 0, NaN, undefined, and null to false.
  • Turn the numeric
var num1 = prompt(Number of '1')		// Enter: 123abc
varNum2 = prompt (" number2')// Enter: 456
console.log(num1+num2);			// Result: 123abc456
console.log(parseInt(num1)+parseInt(num2)); // Result: 579
Copy the code
To transfer data Number() parseInt() parseFloat()
Numeric string Convert to the corresponding number Convert to the corresponding number Convert to the corresponding number
An empty string 0 NaN NaN
A string beginning with a number NaN Convert to a number that starts with a number Convert to a number that starts with a number
A non-numeric starting string NaN NaN NaN
null 0 NaN NaN
undefined NaN NaN NaN
false 0 NaN NaN
true 1 NaN NaN
console.log(parseInt('123abc'));		// Result: 123
console.log(parseInt('F'.16);	// Result: the parameter after 15 indicates 16
Copy the code
  • String can convert any type to a String. ToString () can convert any type to a String. ToString () has no toString methods except null and undefined.