Form of programming

Process-oriented: a mechanical idea, such as for loops…

Object-oriented: JS semi-oriented processes tend to be object-oriented/Java…

//1. Typeof operator: undefined function (number Boolean string object)

example

// var num = true; // console.log(typeof(num)); Var num = [1,2]; // console.log(typeof(num)); // var num = null; // console.log(typeof(num)); // var num = function(){}; // console.log(typeof(num));Copy the code

// Typeof can also add Spaces when parentheses are used

example

    //  var num = undefined;
    //  console.log(typeof num);
Copy the code

2.Type conversion is unique to JS

/ parseInt int /parseFloat /Boolean / /
// number converts to a number

Example a number: NaN

    // var demo = undefined;
    // var num = Number(demo);
    // console.log(typeof(num)+":" + num);
Copy the code

The second case number: NaN

    // var demo = "a";
    // var num = Number(demo);
    // console.log(typeof(num)+":" + num);
Copy the code

Case number three: NaN

    // var demo = "true";
    // var num = Number(demo);
    // console.log(typeof(num)+":" + num);
Copy the code

Number four: 1

    // var demo = true;
    // var num = Number(demo);
    // console.log(typeof(num)+":" + num);
Copy the code

Case number five: NaN

    // var demo = "NaN";
    // var num = Number(demo);
    // console.log(typeof(num)+":" + num);
Copy the code
// parseInt is converted to an integer, regardless of non-numbers such as true,undefined– >NaN attribute :number

Example a number: NaN

    // var demo = true;
    // var num = parseInt(demo);
    // console.log(typeof(num)+":"+num);
Copy the code

Two cases number: 2833

// var demo = "b11"; // var num = parseInt(demo,16); Converted to integer 16 is "a" converted to decimal based on hexadecimal; Radix2-36 // console.log(typeof(num)+":" +num);Copy the code

100 cases of three

    // var demo = "100px";
    // var num = parseInt(demo);
    // console.log(typeof(num)+":"+num);
Copy the code
// parseFloat is converted to a normal decimal number with the property number
// var demo = "100.2.3 ABC "; // var num = parseFloat(demo); // console.log(typeof(num)+":"+num);Copy the code
// String is converted to the string attribute string

// to string

Case a string: 12

    //  var demo = 12;
    //  var num = demo.toString();
    //  console.log(typeof(num)+":"+num);
Copy the code

Undefined and null cannot use toString

    // var demo = null;
    //  var num = demo.toString();
    //  console.log(typeof(num)+":"+num);
Copy the code

Example 3 to base 8 ==string:12

    //  var demo = 10;
    //  var num = demo.toString(8);
    //  console.log(typeof(num)+":"+num);
Copy the code

Example 4 converts a binary number to hexadecimal

// var num = 1000; // var test = parseInt(num,2); // console.log(test.tostring (16)); // Convert decimal to hexadecimalCopy the code
Implicit type conversions implicitly call explicit methods

Implicit type conversion

/ / example 0

// var num = 1 -"1"; // console.log(typeof(num) +":" + num); // Attribute // valueCopy the code
Example 1 isNaN is a non-number, check whether it is true or false —–> corresponding Number
//       console.log(isNaN("abc")); 
Copy the code

// // The implicit conversion process – put the Number inside the Number(” ABC “), which is converted to NaN <–> NaN is true

//      console.log(isNaN(null));        false
        console.log(isNaN(undefined));   true
Copy the code

// null is 0 in Number, and undefined is NaN

    // var num = null;
    // var demo = Number(num);
    // console.log(typeof(demo)+":"+demo);
Copy the code
The following implicit call to the type property becomes number

++

// var a = "123"; // a++; // select * from '123' where '123' = '123'; =124 // var a = "abs" // a ++; // "abs" is not a number, resulting in NaN, which is implicitly converted to typeof(a):numberCopy the code

Plus minus one dollar plus or minus

// var a = +"abc"; // console.log(typeof(a)+":"+a); Implicitly converted to number:NaNCopy the code

Plus plus example

// var a = a + 1; // console.log( typeof(a)+ ":" +a); Results: the number: NaNCopy the code

The difference **—— + + if one of the two sides is a string, both end up as string**

// var a = "a" + 1; // console.log( typeof(a)+ ":" +a); Results: the string: a1Copy the code

Multiplication sign example

// var a = "1" * 1; // console.log(typeof(a)+":"+a); Results: the number: 1Copy the code

Example of comparison strings and numbers are converted to numbers for comparison.

// var a = "3">2; // console.log(typeof(a)+":"+a); Results: the Boolean: true,Copy the code

But strings and strings compare without type conversions to ASC codes

    // var a = "3">"2";
    // console.log(typeof(a)+":"+a);
Copy the code

Is equal to the = =And the range! An example of =

    // var a = 1 == "1";
    // console.log(typeof(a)+":"+a);
Copy the code
// var a = 1 ! = true; // console.log(typeof(a)+":"+a);Copy the code

* * = = = and! ==** No type conversions occur, left and right must be equal // Special case NaN === NaN– > false

An error occurs if a variable is not defined

// console.log(a); // console.log(typeof(a)); // Console. log(typeof(a));Copy the code

Special case returns string undefined… typeof(typeof(a))=”string”—typeof(a)=”undefined”

//  console.log(typeof(typeof(a)));
//  console.log(typeof(typeof(a)+":"+(typeof(a))));
Copy the code

test

// alert(typeof(a)); // alert(typeof(undefined)); // undefined pops up. In the console typeof(a) returns undefined as a stringCopy the code
// alert(typeof(NaN)); // Return number as a stringCopy the code
// alert(typeof(null)); // Return object as a stringCopy the code
// var a = "123abc"; // alert(typeof(+a)); // Return number as a stringCopy the code
// alert(typeof(!! a)); // Return string type BooleanCopy the code
// alert(typeof(a+"")); / / display the stringCopy the code
    // alert(1=="1");
Copy the code
// alert(NaN == NaN);
Copy the code
    // alert(NaN == undefined);
Copy the code
// alert("11"+11); // both become the string 1111Copy the code
// alert(1 === "1");
Copy the code
    // alert(parseInt("123abc"));
Copy the code
// var num = 123123.345789; // alert(num.toFixed(3)); Keep three decimal placesCopy the code
// typeof(typeof(a)); // typeof(a) returns "undefined", typeof(a) returns "string";Copy the code