JS basic content JS introduces the data type conversion of constituent variables

Preface: these js content notes are refined by me according to the dark horse course, and I just want to record while studying.

The browser is divided into two parts

--Rendering engine and js engine

Rendering engine: it is used to parse HTML and CSS, commonly known as kernel, such as blink of chrome browser and webkit of old version

JS engine: also known as JS interpreter, it is used to read JavaScript code in web pages, process it and run it, such as V8 of chrome browser

The browser itself does not execute the JS code, but executes the JS code through the built-in JavaScript engine (interpreter). When the JS engine executes the code, it interprets the source code of each sentence line by line (converted into machine language) and then executed by the computer. Therefore, the JavaScript language is classified as a scripting language and will be interpreted and executed line by line.

JS composition

1.ECMAScript

ECMAScript is a programming language standardized by ECMA International (the former European Computer Manufacturers Association). This language is widely used on the world wide web. It is often called JavaScript or JScript, but in fact, the latter two are the implementation and extension of ECMAScript language.

ECMAScript: ECMAScript specifies the programming syntax and basic core knowledge of JS. It is a set of JS syntax industry standards jointly followed by all browser manufacturers.

2.DOM -- Document Object Model

Document Object Model (DOM) is a standard programming interface recommended by W3C to deal with extensible markup language. Through the interface provided by Dom, you can operate various elements on the page (size, position, color, etc.).

3.BOM - browser object model

BOM (Browser Object Model) refers to the browser object model. It provides an object structure that is independent of content and can interact with the browser window. Through BOM, you can operate the browser window, such as pop-up box, control browser jump, obtain resolution, etc.

notes

Single line note://

Multiline comment:/**/

Three print output modes

//Input box

prompt('Please enter your student number ');

//The output of the pop-up alert box is displayed to the user

alert('always believe that good things are coming ');

//The console prints information to the programmer

console.log('Here is the console information ');

variable

Variable declaration: VaR, age, let (let will be used later when ES6 is important)

Declare variable special cases

Declare no assignment

let sex; //undefined

Direct assignment without declaration

qq = 2995404392;// Can be used directly (global variable, not recommended)

js is a weakly typed language. The type of a variable is determined only when the value is given.

js dynamic language belongs to variable data type, which can be transformed

Digital:

 <script>
        let num = 10;//num type number
        let PI = 3.14;//PI digital
            //1. Octal 0 ~ 7 in our program, the number preceded by 0 represents octal
        let num1 = 010;
        console.log(num1);//010 to decimal 8
        let num2 = 012;
        console.log(num2);
            //2. Hex 0~9 a~f
        let num3 = 0xb;
        console.log(num3);
            //Digital maximum
        console.log(Number.MAX_VALUE);
            //Digital minimum
        console.log(Number.MIN_VALUE); 
            //Infinity
        console.log(Number.MAX_VALUE*2);//Infinity
            //Infinitesimal
        console.log(-Number.MIN_VALUE*2);//-Infinity
            //Non numeric
        console.log('warm'-100);//NaN
​
        //isNaN() this method is used to judge non numbers and return a value. If it is a number, it returns false. If it is not a number, it returns true
        console.log(isNaN(12));//false
    console.log(isNaN('shuzi'));//ture
    </script>

String type

<script>
        //String escape character
        /*   
        \n Line feed
        \\ Single slash
        \' Single quotation mark
        \" Double quotation mark
        \t tab indent
        \b Space, blank
        */
​
        //1. Detect and obtain the length of string type
        let str  = 'TIwarm';
        alert.length(str);
        //2. String splicing
        console.log('Hello!'+'warm');
        console.log('Hello'+true);
        console.log(12+12);
        console.log('12'+12);
 
    </script>

Boolean type

 <script>
        let flag = true;
        let flag1 = false;
        console.log(flag+1);//true participates in the addition operation when 1 looks at it
        console.log(flag1+1);//false participate in addition when 0
​
        let variable = undefined;
        console.log(variable+1);//NaN result is not a number
        let space = null;
        console.log(space+'pink')//nullpink
        console.log(space+1);//1
    </script>

View data type value -- typeof

let num =10;

console.log(typeof num);

Data type conversion

Other conversion strings

1.tostring()

Example: var num = 1;

alert(num.toString());

2.String() cast type

Example: var num = 1;

alert(String(num));

3. Plus sign splicing string

Example: var num = 1;

alert(num + 'I am');

Revolution font

1. ParseInt (variable) can convert a character type to a number type to obtain an integer

var age = prompt('Please enter your age ');

console.log(parseInt(age));

2. Parsefloat (variable) can convert character type to number type to get decimal floating point number

console.log(parseFloat('3.14'));

3. Use number (variable)

console.log(Number('123'));

4. Arithmetic operation - * / implicit conversion is used

Turn Boolean

I actually listed the following special false values

Boolean()Function;

        console.log(Boolean(''));//false
        console.log(Boolean(0));//false
        console.log(Boolean(NaN));//false
        console.log(Boolean(null));//false
        console.log(Boolean(undefined));//false
​
        console.log(Boolean('123'));//true
        console.log(Boolean('Hello'));//true

Keywords: Javascript Front-end

Added by Burns on Sun, 12 Dec 2021 11:19:34 +0200