当前位置:网站首页>First acquaintance with JS (programming suitable for beginners)

First acquaintance with JS (programming suitable for beginners)

2022-07-23 20:59:00 Geek Yunxi

 // Ctrl+/   Double diagonal , Comment line

        // Ctrl+Shift+/   Comment lines  Alt+Shift+A

        /*

         * Variable : Identifier of data stored in computer memory , The data of the operation is operated in memory

         * effect : Used to store and manipulate data

         * How to use variables to store data :var Variable name = Stored data ;

         * Declare variables with var

         * Declaration of variables : Yes var There are variable names

         * Variable initialization : Yes var There are variable names Valuable

         */

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>
<body>
    <script>
    
        //  Statement 
        var number;
        var a, b, c, d;//  Declare more than one variable at a time , No assignment 
        //  assignment 
        number = 10;
        console.log(number);

        //  Store a number 20
        var num = 20;
        console.log(num);// 20
        //  Store a name 
        var name = "Sherry";
        console.log(name);

        num = num + 10;
        console.log(num);// 30
        num = num + 20;
        console.log(num);// 50

        alert(name);//  bounced   Blocking process 
        
        
        
    </script>
</body>
</html>

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //  Exchange of variables 
        var num1 = 10;
        var num2 = 20;

        // ①  Exchange with third-party variables 
        var temp;
        //  hold num1 The variables of are stored in temp in 
        temp = num1;// 10
        //  hold num2 The variables of are stored in num1 in 
        num1 = num2;// 20
        //  hold temp The variables of are stored in num2 in 
        num2 = temp;// 10

        // ②  Used to calculate 
        //  hold num1 and num2 The sum is equal to 30, Reassign to num1
        num1 = num1 + num2;// 30
        num2 = num1 - num2;// 10
        num1 = num1 - num2;// 20
    </script>
</body>
</html>

 /* 
         * Basic code specifications :
         * 1、 Every line js There should be a semicolon at the end ;
         * 2、js It's case sensitive :var n = 10; var N = 10;
         * 3、js You can use single quotation marks , You can also use double quotes .
         *
         * Specification of variable names :
         * 1. Variable names must be meaningful ;
         * 2. Usually in letters 、$ Symbol 、_ Start with an underline , There can be letters in the middle and after 、 Numbers 、$、 Underline , Cannot start with a number ;
         * 3. The initial letter is usually lowercase , Follow the hump nomenclature : If the variable name is more than one word , First word lowercase , All the following words are capitalized var loveSherry; var yiRenZhiXia;;
         * 4. It must not be a keyword or reserved name :var,let,const,new
         */ 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
       
        //   Declare multiple variables , One assignment at a time 
        var num1, num2, num3, num4;
        num1 = 1;
        num2 = 2;
        num3 = 3;
        num4 = 4;
        console.log(num1, num2, num3, num4);

        //  Declare multiple variables , simultaneous assignment 
        var a = 10, b = 20, c = 30;
    </script>
</body>
</html>

 /*

         * The operator : Some symbols , To calculate

         * Arithmetic operator :+ - * / %( Remainder )

         * Arithmetic expressions : Expressions connected by arithmetic operators

         * ① Unary operator : This operator only needs one operand to operate on the symbol ++ --

         * ② Binary operator : Which requires two operands var num = 10 + 5;

         * ③ Ternary operator : Three operands are required , When writing conditional judgment → Ternary expression

         * ④ Composite operators :+= -= *= /= %=

         * ⑤ Relational operator :> < >= <= ==( Not strictly equal to ) !=( Not strict is not equal to ) ===( Strictly equal to ) !==( Strict is not equal to )

         *               Set up return true, Not established to return false

         * ⑥ Logical operators :

         *              && also → As long as there's an expression for false, The whole result is false One false is false

         *              || perhaps → As long as there's an expression for true, The real result is true True is true

         *              ! Take the , Take the opposite

         * ⑦ Assignment operator :=

         */

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //  var num = 9 / 4;
        //  console.log(num);// 2
        //  var num1 = 9 % 4;
        //  console.log(num1);// 1

        //  var num1 = 10;
        //  num1++;// num1 = num1 + 1
        //  console.log(num1);
        //  ++num1;
        //  console.log(num1);

        //  ++ before , First plus , Post operation 
        var num1 = 5;
        ++num1;// 6
        var num2 = 6;
        console.log(num1 + ++num2);// 13
        //  ++ After , Calculate first , After add 
        console.log(num1 + num2++);// 12

        var num1 = 10;
        num1 += 10;//  amount to num1 = num1 + 10;

        var num1 = 10;
        var num2 = 20;
        console.log(num1 > num2 && 5 < 6);// false
        console.log(num1 > num2 || 5 < 6);// true

        
    </script>
</body>
</html>

 

/*

         * js Simple data types of :

         * 1. Numeric type Number

         * 2. String type String

         * 3. Boolean type booleen

         * 4. Null value null

         * 5. Undefined undefined

         * js Composite data type :

         * 1. object Object

         * 2. function function

         * number: Numeric type ( Integers and decimals , Floating point numbers )

         * string: String type ( Values are generally enclosed in single or double quotation marks )

         * booleen: Boolean type ( There are only two values true/false 1/0)

         * null: Empty type , It's worth only one null, When the point of an object is empty , At this point, it can be assigned null

         * undefined: Undefined type , The value is just one undefined, When declaring variables , No assignment , The result is undefined

         * Get the data type of the variable :typeof

         * grammar :typeof Variable

example  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         var num = 10;
         var str = "10";
         var flag = true;
         var $null = null;
         var unde;
         var obj = new Object();
         var f1 = function() {

         }

         console.log(typeof num);// number
         console.log(typeof str);// string
         console.log(typeof flag);// boolean
         console.log(typeof $null);// object
         console.log(typeof unde);// undefined
         console.log(typeof obj);// object
         console.log(typeof f1);// function
    </script>
</body>
</html>

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
        //  One 、Number type : Integers and floating point numbers ( decimal )
        // var num1 = 10;
        // var num2 = 10.33;//  Floating point numbers 
        
        //  Two 、 Range of numeric types : Maximum and minimum 
        // console.log(Number.MAX_VALUE);//  Maximum 1.7976931348623157e+308
        // console.log(Number.MIN_VALUE);//  minimum value 5e-324  5 multiply 10 Of -324 Power 
        //  infinity :Infinity
        //  An infinitesimal :-Infinity

        //  3、 ... and 、 Don't judge that two floating-point numbers are equal 
        // var x = 0.1;
        // var y = 0.2;
        // console.log(x + y);// 0.3?  It didn't turn out to be 0.3, It is 0.30000000000000004
        // console.log(0.07 * 100);//  No 7, It is 7.000000000000001

        //  Four 、 Numerical judgment 
        var num;
        console.log(num + 10);// NaN → not a number
        // NaN Not equal to any value , Including himself 
        //  Do not use NaN verification NaN
        // = assignment   == be equal to 
        console.log(num + 10 == NaN);// false
        //  How to verify whether the result is NaN, Use isNaN( Variable name )
        // isNaN → is not a number
        console.log(isNaN(num));// true →  No number
        var num2 = 100;
        console.log(isNaN(num2));// false →  yes number
    </script>
</body>
</html>

01.Number type  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
        var str1 = "abc";
        var str2 = "Sherry";
        var str3 = "hello word!"

        //  String length : Variable name .length
        console.log(str1.length);// 3
        console.log(str2.length);// 6
        console.log(str3.length);// 11

        //  Escape character 
        // \n Line break   \t Tabulation   \b Space   \r enter   \\ Slash \  \" Double quotes   \' Single quotation marks 

        //  String splicing   use + link 
        console.log(11 + 11);// 22
        console.log("11" + 11);// 1111
        console.log("hello" + "word");// helloword
        console.log("sss" + true);// ssstrue

        // 1. Just one string on either side , that + It's string concatenation 
        // 2. If both sides are numbers , that + It's the arithmetic function 
    </script>
</body>
</html>

原网站

版权声明
本文为[Geek Yunxi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207232050205380.html