And JavaScript's "love" isn't coming?

First acquaintance: meeting JavaScript for the first time


        JavaScript is a literal script language. It is a dynamic type, weak type, prototype based language with built-in support of types. Its interpreter is called JavaScript engine. It is a part of the browser and is widely used in client-side scripting language. It was first used on HTML (an application under standard General Markup Language) web pages to add dynamic functions to HTML web pages.
        Generally speaking, it is a scripting language running on the client. What is a scripting language? Scripting language, also known as extended language, or dynamic language, is a programming language used to control software applications. Scripts are usually saved in text (such as ASCII) and interpreted or compiled only when called. Scripting languages do not need to be compiled and are interpreted and executed line by line by JavaScript.


  • Embed dynamic text in HTML pages
  • Respond to browser events
  • Reading and writing HTML elements
  • Validate the data before it is submitted to the server
  • Detect visitor's browser information
  • Control cookies, including creation and modification
  • Server side programming based on Node.js Technology


(1) Scripting language. JavaScript is an interpretive script language. C, C + + and other languages are compiled before execution, while JavaScript is interpreted line by line during the running process of the program.

(2) Object based. JavaScript is an object-based scripting language. It can not only create objects, but also use existing objects.

(3) Simple. The JavaScript language uses weak variable types and does not have strict requirements on the data types used. It is a scripting language based on Java basic statements and control, and its design is simple and compact.

(4) Dynamic. JavaScript is an event driven scripting language. It can respond to user input without going through the Web server. When visiting a Web page, the mouse clicks, moves up and down, and moves the window in the Web page. JavaScript can directly respond to these events.

(5) Cross platform. JavaScript scripting language does not depend on the operating system and only needs the support of the browser. Therefore, a JavaScript script can be brought to any machine for use after writing. On the premise that the browser on the machine supports JavaScript scripting language, JavaScript has been supported by most browsers at present.

Acquaintances: take the initiative to understand everything related to JavaScript


We can generally understand this as: a container for storing data and obtaining data through variable names;


     var Variable name = Variable value;    (variable initialization)

     Variable name naming convention

  • It is composed of letters (A-Za-z), numbers (0-9), underline (), dollar sign ($), such as usrage, num01_ name
  • Strictly case sensitive. var App; And var App; Are two variables
  • Cannot start with a number. 18age is wrong
  • Cannot be keyword or reserved word. For example: var. for. while
  • Variable names must be meaningful
  • Follow the hump nomenclature. The first letter is lowercase, and the first letter of the following word needs to be capitalized. myFistName
  • Youdao ICIBA

data type

     Simple data type

  • Number type number
    be careful:
             1. Add 0 012 before octal;
             2. Hexadecimal plus 0x 0xa=10;
             3. Maximum value of digital console. Log (number. Max_value);
             4. Minimum value of digital console. Log (number. Min value);
             5.alert (Infinity), representing infinity, greater than any value;
             6.alert(-Infinity), representing infinitesimal, less than any value;
             7.alert (NaN), Not a number, represents a non numeric value;

  • String string
    be careful:
             1. The string must be quoted;
             2. Double quotation marks and single quotation marks are used separately, and single quotation marks are recommended;

  • Null value null
    be careful:
             1. The result of adding to the string is null string;
             2. The result of adding with the value is the value;

  • Boolean
    be careful:
             1.FALSE: if it is false, participate in the addition operation as 0;
             2. If true, participate in the addition operation as 1;

  • The declared variable is not given the value undefined
    be careful:
             1. The result of adding with the value is NaN;
             2. The result of adding to the string is undefined string;

     Character type conversion

  • Convert to character
1.variable.toString( )
var num = 10;
var str =num.toString( ) ;  

var num = 10;
console.log( num );

3.Splice string (implicit conversion)
var num = 10;
console.log( num +'');
  • Convert to numeric
1.parseInt Convert to integer
var str='3.1415';
console.log(parseInt(str));  //The output is 3 (only the integer part is taken and will not be rounded)

2.parseFloat Convert to floating point
var str='3.1415';
console.log(parseFloat(str)); //The output result is 3.1415 (digital at this time) 

var str='3.1415';

4.Arithmetic operation (implicit conversion) - * / (yes, addition is not allowed)  
var str='3.1415';
console.log(str - '0');


     Operator classification

  • Arithmetic operator
    Arithmetic operators are what we usually call addition, subtraction, multiplication, division, remainder, etc., but it should be noted that:
    1. The computer needs to be converted into binary execution program, so there will be floating-point accuracy problems;
    2. Two floating-point numbers cannot be judged equal;

  • Relational operator (comparison operator)

  • Logical operator

  • Assignment Operators

  • Increment operator decrement operator
    Increment:++    Decrement: --

Front:++ variable      Self addition first, and then operation  
Post: Variables ++      First perform the operation, and then perform the self addition  

When used alone, the effect of pre increment and post increment is the same

var num =  1 ;
var num1 = 1 + num++; //At this time, the value of num1 is 2. Num first operates on num1 and then adds itself;
var num2 = 1 + ++num; //At this time, the value of num1 is 3, and num is added to num2 before operation;

Love: traveling in the world of code with JavaScript

Process control

It describes the order in which the program is executed when the program is executed;


  • Sequential structure: executed from top to bottom;
  • Branch: execute different codes under different conditions to get different results;
  1. if statement: execute only when the conditional expression is satisfied, otherwise skip and do not execute;
if (Conditional expression) { Statement to execute }

var a = 5;
var b = 6;
if (a > b){ console.log('When the conditional expression is true, print this statement');  }
  1. if else statement: judge the conditional expression of if. If the conditions are met, execute the statements in if, otherwise execute the statements in else; (if and else must execute one of them)
if (Conditional expression) {3
      Execute statement 1
} else{
      Execute statement 2

var a = 5;
var b = 6;
if (a > b){ 
     console.log('At this point, the conditional expression holds and the statement is printed');  
}else {
     console.log('If the conditional expression does not hold, print this statement');  
  1. if else if statement: if the conditional expressions in the if are not satisfied, it will continue to judge. When all the conditional expressions are not satisfied, the last statement will be executed;
if(Conditional expression 1){
      Execute statement 1
}else if(Conditional expression 2){
      Execute statement 2
}else if(Conditional expression 3){
      Execute statement 3
}else {
      Execute statement 4
}  // The number of if else statements is unlimited

  1. switch statement: match with the value value of case. If it matches, execute the statement (must be congruent: numbers and data types must be equal). If they do not match, execute the last statement;
case value1: 
      Execute statement 1;
case value2: 
      Execute statement 2;
case value2: 
      Execute statement 2;
      The last execution statement;

  1. Ternary expression
Conditional expression? Expression 1: expression 2
 Conditional expression result true: returns the value of expression 1
 Conditional expression result false: returns the value of expression 2



     Using loops can repeatedly execute code and improve the efficiency of code execution.

Cyclic classification

  • for loop
for(Initial variable ; Conditional expression ; Operation expression){ Circulatory body }

Initialization variable: ordinary variable is used as a counter (only executed once)
Condition expression: used to determine whether a loop continues to be executed. If the conditions are met, the loop will be executed but not terminated;
Operation expression: the code executed at the end of each loop. It is often used to update (increment or decrement) counter variables

for(var i = 1; i <= 100 ; i++){
     console.log('Print 100 sentences: Hello!')
 }// Multiple for loops can be embedded in the for loop: the external loop executes once and the internal loop executes all;
  • while loop: enter the loop when the result of the conditional expression is true; Exit the cycle until it fails;
while(Conditional expression){  Circulatory body  }

var num = 1;
while(num <= 100){
    console.log('I'm cycling!');
    num++; // Without self addition, it will enter a dead cycle
  • do... while loop: execute it once before judging the conditional expression; If it is established, it will continue to be implemented; if it is not established, it will not be implemented;
    Circulatory body
    }while(Conditional expression)
var num = 1;

     console.log('I'm cycling!');
      num++; // Without self addition, it will enter a dead cycle
    }while(num <= 100)


Array is a data set in which each data type can be stored;

Creation method

  • Create new code with new
var Array name = new Array();
var arr = new Array();
  • Creating arrays with array literals
var Array name = [ Array contents ];

var arr = [1,12,54,68,658,8454,99];

About array elements

  • Index (subscript): used to access the ordinal number (starting from 0) of the elements in the array
  • Syntax format: array name [index number]
  • Traversing the array: take the array elements from beginning to end;
  • Array length: array name. Length


     On the road of falling in love with JavaScript, we will go farther and farther! The training of "love" is the most growing. Maybe we will experience a lot of ups and downs along the way. With endless hair and endless code, but I love him!

Tags: Javascript node.js Front-end html5

Posted on Sat, 18 Sep 2021 17:34:53 -0400 by manyamile