-
\
-
/*
-
* :: The data type refers to the type of literals
-
* There are six data types in JS.
-
* :: String
-
* :: Number Numerical value
-
* :: Boolean
-
* :: Null Null
-
* :: Undefined
-
* :: Object objects
-
*
-
* where String Number Boolean Null Undefined is a basic data type
-
* :: Whereas Object is a reference data type
-
*/
-
-
/*
-
* String
-
* - strings need to be caused by quotes in JS
-
* - Use either double or single quotes, but don't mix them up!
-
* - quotes cannot be nested, double quotes cannot be put in double quotes, single quotes cannot be put in single quotes
-
*/
-
var str = 'hello';
-
-
str = 'I said: "What a beautiful day!"' ;
-
/*
-
We can use \ as an escape character in a string.
-
You can use \ to escape when representing some special symbols.
-
-
\" denotes "\"
-
\' denotes '
-
\n means change
-
The \t tab - feels like a space.
-
\\\ Indicates\
-
* */
-
str = "I said:\ "It's a beautiful day today\t! \"";
-
-
// str = "\\\\\\";
-
-
(str);
————————————————————————————————————————
-
/*
-
* All values in JS are of type Number.
-
* :: Includes integers and floating point numbers (decimals)
-
*
-
* :: Maximum value of a number that can be expressed in JS
-
* Number.MAX_VALUE
-
* 1.7976931348623157e+308
-
*
-
* Number.MIN_VALUE Minimum value greater than 0
-
* 5e-324
-
*
-
* If the number expressed using Number exceeds the maximum value, it returns a
-
* Infinity denotes positive infinity
-
* -Infinity means negative infinity
-
* Checking Infinity with typeof also returns number
-
* :: NaN is a special number that stands for Not A Number
-
* Checking for a NaN using typeof also returns number
-
*/
-
// Number 123
-
// Number 123
-
var a = 123;
-
//String 123
-
var b = "123";
-
var result = typeof a;
-
var result2 = typeof b;
-
console.log(typeof result);
-
console.log(typeof result2);
'
(of a computer) run
type The return value of this variable is the string representation of the type, which is a string.
Course Address: Liao Xuefeng j2ee Distributed Architect the first phase of the god course is here!
/youzhi/
That's something to figure out thoroughly!
And the return type is the lowercase form of the string, i.e. string number boolean null undefined object!!!!
-
/*
-
* :: Boolean
-
* :: There are only two Boolean values, mainly used to make logical judgments
-
* true
-
* - indicates true
-
* false
-
* - indicates false
-
*
-
* :: Using typeof to check a boolean value returns boolean
-
*/
-
-
var bool = false;
-
-
(typeof bool);
-
(bool);
-
/*
-
* :: The Null type has only one value, which is null
-
* :: The value null is used exclusively to denote a null object
-
* :: Using typeof to check for a null value returns object
-
*
-
* :: The Undefined type has only one value, undefind
-
* :: When a variable is declared but not assigned a value, its value is undefined
-
* Using typeof to check for an undefined also returns undefined
-
*/
-
var a = null;
-
-
var b = undefined;
-
-
(typeof b);
-
/*
-
* :: Converting other data types to String
-
* :: Modality I:
-
* :: - Call the toString() method of the data type being converted
-
* - this method does not affect the original variable, it returns the result of the conversion
-
* - but note: there is no toString() method for the values null and undefined.
-
* :: If their methods are called, an error is reported
-
*
-
* :: Modality II:
-
* - call the String() function and pass the converted data as an argument to the function
-
* - When using the String() function to do a forced type conversion, the
-
* :: For Number and Boolean, it's actually a call to the toString() method.
-
* :: But for null and undefined, the toString() method is not called
-
* It converts null directly to "null".
-
* Converts undefined directly to "undefined".
-
*
-
*/
-
-
var a = 123;
-
-
// Call the toString() method of a
-
// Calling xxx's yyyy() method is ()
-
a = ();
-
-
a = true;
-
a = ();
-
-
a = null;
-
//a = (); //Error message
-
-
a = undefined;
-
//a = (); //Error message
-
-
-
a = 123;
-
-
// Call the String() function to convert a to a string.
-
a = String(a);
-
-
a = null;
-
a = String(a);
-
-
a = undefined;
-
a = String(a);
-
-
(typeof a);
-
(a);
-
/*
-
* :: Converting other data types to Number
-
* :: Conversion mode I:
-
* :: Use of the Number() function
-
* - strings --> numbers
-
* :: 1. If it is a purely numeric string, it is converted directly to a number
-
* :: 2. Convert to NaN if there are non-numeric elements in the string
-
* :: 3. If the string is an empty string or a string with all spaces, it is converted to 0
-
* - Boolean --> numbers
-
* true to 1
-
* false to 0
-
*
-
* - null --> number 0
-
*
-
* - undefined --> number NaN
-
*
-
* :: Conversion mode II:
-
* - This approach is specifically used for strings
-
* - parseInt() Converts a string to an integer.
-
* - parseFloat() converts a string to a floating point number
-
*/
-
-
var a = "123";
-
-
// Call the Number() function to convert a to Number.
-
a = Number(a);
-
-
a = false;
-
a = Number(a);
-
-
a = null;
-
a = Number(a);
-
-
a = undefined;
-
a = Number(a);
-
-
a = "123567a567px";
-
// call parseInt () function to convert a to Number
-
/*
-
* parseInt() removes valid integer content from a string.
-
* :: Then converted to Number
-
*/
-
a = parseInt(a);
-
-
/*
-
* :: parseFloat() is similar to parseInt(), except that it gets a valid decimal number.
-
*/
-
a = "123.456.789px";
-
a = parseFloat(a);
-
-
/*
-
* :: If parseInt() or parseFloat() is used for non-Strings
-
* It will first convert it to a String and then manipulate the
-
*/
-
a = true;
-
a = parseInt(a);
-
-
a = 198.23;
-
a = parseInt(a);
-
-
(typeof a);
-
(a);
-
/*
-
* Operators are also called operators
-
* :: Operators that allow one or more values to be manipulated and the results to be obtained
-
* :: For example, typeof is an operator that can be used to obtain the type of a value.
-
* It will return the type of the value as a string
-
* number string boolean undefined object
-
*
-
* :: Arithmetic operators
-
* When performing operations on values that are not of type Number, the values are converted to Number and then used in the operations.
-
* Any operation with NaN yields NaN.
-
*
-
* +
-
* + can perform an addition operation on two values and return the result
-
* :: If addition is performed on two strings, a collocation is done
-
* will concatenate the two strings into a single string and return
-
* Any value that does addition with a string will be converted to a string first, and then it will do the string collocation with the string
-
* -
-
* - can perform subtraction on two values and return the result
-
*
-
* *
-
* * Can multiply two values.
-
* /
-
* / can perform division on two values
-
* %
-
* :: % Modulo operation (taking a remainder)
-
*/
-
var a = 123;
-
-
var result = typeof a;
-
-
//(typeof result);
-
-
result = a + 1;
-
-
result = 456 + 789;
-
-
result = true + 1;
-
-
result = true + false;
-
-
result = 2 + null;
-
-
result = 2 + NaN;
-
-
result = "Hello" + "Big Handsome Guy";
-
-
var str = "Hoeing," +
-
"Sweat the sweat of the brow," +
-
"Who knows what's on the plate," +
-
"Grain for Grain".
-
-
-
result = 123 + "1";
-
-
result = true + "hello";
-
-
// Any value added to a string is converted to a string and a collocation is done.
-
/*
-
* :: We can use this feature to convert an arbitrary data type to String
-
* We just need to add a "" to any datatype to convert it to a String.
-
* :: This is an implicit type conversion, done automatically by the browser, which actually calls the String() function as well
-
*/
-
var c = 123;
-
-
c = c + "";
-
-
//c = null;
-
-
//c = c + "";
-
-
-
//(result);
-
//(typeof c);
-
//("c = "+c);
-
-
result = 1 + 2 + "3"; //33
-
-
result = "1" + 2 + 3; //123
-
-
result = 100 - 5;
-
-
result = 100 - true;
-
-
result = 100 - "1";
-
-
result = 2 * 2;
-
-
result = 2 * "8";
-
-
result = 2 * undefined;
-
-
result = 2 * null;
-
-
result = 4 / 2;
-
-
result = 3 / 2;
-
-
/*
-
* Any value that does the - * / operation is automatically converted to Number.
-
* :: We can use this feature to do implicit type conversions
-
* :: It can be converted to Number by providing a value of -0 *1 /1.
-
* :: The principle is the same as the Number() function, which is simpler to use
-
*/
-
-
var d = "123";
-
-
//("result = "+result);
-
-
d = d - 0;
-
-
/*(typeof d);
-
(d);*/
-
-
result = 9 % 3;
-
result = 9 % 4;
-
result = 9 % 5;
-
-
("result = "+result);
-
-
</script>
-
-
var a = null;
-
var a= undefined;
-
(+a);
-
-
-
/**
-
* + a
-
*
-
* If a is not a numeric type, first convert a to a numeric type, then go to the budget, so you can use
-
* +a Hermit converts to a numeric type!
-
-
*/
-
/*
-
* :: Unary operators, which require only one operand
-
* + positive sign
-
* - the plus sign does not have any effect on the numbers
-
* - negative sign
-
* - Negative sign can invert the negative sign on a number
-
*
-
* - for values not of type Number.
-
* It will be converted to Number first, and then in the operation
-
* :: It is possible to use +, on a different datatype, to convert it to a number.
-
* :: It works like the Number() function.
-
*/