[zhilaitang learning notes]_ JavaScript knowledge

Please pay attention to "zhirentang learning community", address: http://www.zhiliaotang.com/portal.php

1. data type

  • A complex data type
    Object properties and methods: constructor, hasOwnProperty (proprty name), isPrototypeof(object), toString(), valueOf()
  • 5 simple data types

    • String value - string conversion method:

      • The String type consists of zero or more 16 bit Unicode characters. It is a character sequence, that is, a String
      • When assigning values to String variables, you need to use single or double quotation marks
      • The length of a character can be obtained through the length attribute, which is different from the length () method
      • String data types include some special character literals, also known as escape sequences
        • toString()
        • String() - convert any type of value
    • Null value: null

      • As with the undefined type, there is only one value null
      • var a1// Uninitialized, value is undefined
        var a2=null// Initialization, value is null
    • Boolean

      • It is strictly case sensitive. The writing method cannot be changed. It cannot be written as true or true
        • true var a1 = true;
        • false var a1 = false;
    • number

      • value type
        • Integer decimal / octal / hexadecimal
        • Floating point number
          **1 The calculated value exceeds the numerical range of JavaScript, and a positive number will be expressed as Infinity
          Negative number: expressed as -Infinity
          2. when infinity occurs, the next calculation cannot be performed
          3. if you want to determine whether a value is within the value range of JavaScript, you can use the isfinish() function to return true. Otherwise, you can return false
          4. there is a special value NaN in javascript, which indicates that the operand that originally returned a value did not return a value. In ECMAScript, any value divided by a non value will return NaN. ECMAScript uses the isNaN() function to determine whether any type of parameter passed in is "not a value"**
      • Numerical range

        • Minimum value: number Min_ Value
        • Maximum value: number Max_ Value
        • Judgment: isFinity()
      • Non numeric

        • NaN
        • isNaN()
      • Numeric conversion

        • Number() - can be used for any data type
        • parseInt() - - converts a string to a numeric value
        • parsefloat() - - converts a string to a numeric value
    • Undefined value: undefined

      • When using the var operator to define a variable, but the variable is not assigned a value, that is, it is not initialized. At this time, the value of the variable is undefined. The undefined type has only one value, which is undefined.
        • var a1;
          Console Log (A1)// The output is undefined
  • Test data type (typeOf)
    • Boolean: the value is a boolean type
<script>
            var a1 = true;
            var a2 = false;
            console.log("a1 = "+a1);
            console.log("a2 = "+a2);
        </script>

Null; Value is null

  `<script>
        var a1 ; // Uninitialized, value is undefined
        var a2 = null; // Initialization, value is null
        console.log("a1 = "+a1);
        console.log("a2 = "+a2);

    </script>`

Number: the value is a number

<script>
            var a = 100;
            var b = 0;
            var c = "helloworld";
            var d = "100.05";
            console.log("a / b = "+a/b); // Return to infinity
            console.log("isFinite = "+(isFinite(a / b))); // Judge whether the value is within the range
            console.log("isNaN = "+(isNaN(c))); // Determine whether it is a numeric type
            console.log("Number = "+Number(d)); // Convert to numeric type
            console.log("parseInt = "+parseInt(d)); // Convert to integer type
            console.log("parseFloat = "+parseFloat(d)); // Convert to floating point type
        </script>

Undefined: value undefined

<script>
            var a1; // Variable not replicated initialized
            console.log("a1 = "+a1);
        </script>

String: the value is a string

<script>
            var a = "Helloworld";  // String type
            var b = 'helloword' ; // Assignment with single quotation marks
            console.log("a = " + a);
            console.log("b = " + b);
            console.log("Length of string = " + a.length);
            var c = "\""; // Double quotation marks can be changed into ordinary characters by means of backslashes
            console.log("c = "+ c);
        </script>

Object: the value is an object or NUll
Function: value is a function

2. operator

  • Arithmetic operator
    • A++ and ++a
 - var a = 10;
            var b = 3;

            var c = ++a;
            console.log("c="+c);
            console.log("a="+a);

            var d = a++;
            console.log("d="+d);
            console.log("a="+a);

            var e = a--;
            console.log("e="+e);
            console.log("a="+a);

            var f = a/b;
            console.log("f="+f);
Output results:
c=11
a=11
d=11
 a=12
e=12
 a=11
 f=3.6666666666666665
  • Comparison operator
    • ==Difference between = = = and ===
      • ==Are the values of the two books being compared equal
      • ===Compare the values of two numbers, and return true only when the types of two numbers are all equal
  • Logical operator
    • A logical operator is an operation on two Boolean value types, and the result of the calculation is a Boolean value
  • Assignment Operators
  • String + operator
    • Add (concatenate) text values or string variables
<script>
            var a = 10;
            var b = "hello";
            var c = 5;
            var d = true;
            var e = false;
            console.log(a + b);
            console.log(a +b +c);
            console.log(b +a +c);
            console.log(b +a /c);
            console.log(b +a %c);
            console.log(b + ++a);
            console.log(b +(a>c));
            console.log(b +(d&&e));
        </script>
  • Conditional operator
    • variable = boolean_expression ? true_value : false_value;
// Find out what is the largest of the three numbers
            c = a > b ? (a > d ? a:d):(b>d ? b:d);
            console.log("c = "+c);

            //Find out the smallest of the three numbers
            c = a<b?(a<d?a:d):(b<d?b:d);
            console.log("c = "+c);
  • typeof operator

    • What is the data of a variable
<script>
            var a1;
            var a2 =10;
            console.log(a2);
            console.log(typeof a2);
            console.log(typeof(a2));
        </script>

3. control statement

  • if all conditions are true
  • if else execute code when the condition is true, and execute other code when the condition is false
  • If else if... else - use this statement to select one of multiple code blocks to execute
    • Must have if to have else if
  • switch - use this statement to select one of multiple code blocks to execute
  • for loop - automatically repeats the execution of a piece of code
  • while loop - the loop can be executed continuously as long as the specified condition is true
  • do/while executes the code block once. When checking whether the condition is true, the loop will be repeated
  • Eak statement
    • Jump switch statement
    • Jump out of current cycle
  • continue - terminate this cycle and execute the next cycle

Tags: Javascript string

Posted by spetsacdc on Mon, 30 May 2022 21:04:18 +0530