[JavaWeb] Basics of JavaScript (1)

JavaScript: client-side scripting language (used to parse and render for the browser, no need to compile)

  • course
    1. In 1992, Nombase developed C–, which was later renamed ScriptEase
    2. In 1995, Netscape company developed Live Script, and Sun company experts modified it and changed its name to JavaScript
    3. In 1996, Microsoft developed JScript.
    4. In 1997, ECMA specified a standard to unify the encoding of all client script languages.
Basic three layers composition
Presentation layer Consists of user interface and interface code
Business Layer Contains the business and function codes of the system
Data access layer Responsible for completing database access operations
  • Defined in html <script>, the difference between internal and external is whether there is src, src write address and import external js file

  • Primitive data type : "The definition becomes more arbitrary after the introduction of the var type..." "The typeof method depends on the data type"

    1. number: Number. Integer/Decimal/NaN (not a number is a number type that is not a number)
    2. string: character string. The string "abc" "a"'abc'
    3. boolean: true和false
    4. null: An empty placeholder for an object (the output will become object, which is a BUG)
    5. undefined: undefined. If a variable has no initial value, it will be assigned to undefined by default
  • A dynamic webpage refers to a webpage that does not exist before and is dynamically generated by the server after the client sends a request!

    1. Dynamic webpages refer to programs or webpages running on the server, which will return different webpages according to different clients and at different times
  • Comparison operator

    • Comparison method:
      • Same type: direct comparison
        • String: dictionary order (compared one by one bit by bit, just like the sorting method of the contact information in the mobile phone)
      • Different types: convert first and then compare
        • All equal (===): the same type is a prerequisite
  • Logical operator: (short circuit)

    • number: non-zero is true; NaN or 0 is false
    • string: null is false
    • Judge the empty string to simplify writing...
  • Flow control statement: if-else

    • switch (variable): case value (any type of variable can be received in JS)
  • (Special syntax):

    1. If the statement has only one line, it can be omitted; (not recommended)
    2. Use var variables to define local variables; not use global variables (not recommended)

Function object

  • The invocation of the method is related to the name of the method, but has nothing to do with the parameter list (undefined will be assigned directly)
  • Create an object:
    • function f (a,b,c){alert(a+b)}
    • var f = function(a,b,c){alert(a+b)}
  • Attributes:
    • length: the number of formal parameters (can be used for for loop assignment)
    • Method coverage does not report errors
    • When calling a method, the parameter list is not necessarily equal to the method I want to give (you can give less or no parameters)
    • In the method declaration, a built-in object (array) is hidden, and argument encapsulates all actual parameters.
      • argument[0]……

Array object

  • Create array

var arr2 = new Array (3);
var arr3 = [1, 2, 3];

    • Put the element list and give the default length of the Array
    • Various types of elements can be put inside, "abc", 1...
  • method:
    • length property: indicates the length of the array
    • The join("–") method adds separators and joins them into strings
    • push("") method of adding elements (add one or more elements to the end of the array and return the new length.)

Date object

  • Method (note that the Date of the object starts with uppercase when it is created)
    • var date = new Date();
    • toLocaleString(): Returns the local string format of the time corresponding to the current date object
    • getTime(): Get the millisecond value. Returns the difference in milliseconds from the time described by the current object as expected to the zero point on January 1, 1970

Math object

  • method:
    • PI, pi
    • random(): random number between 0-1, left open and right closed
    • ceil(): floor(): round down
    • round(): rounding

RegExp: regular expression object

*   正则表达式:定义字符串的组成规则。
    1.  单个字符:[]
如: a a-zA-Z0-9_
特殊符号代表特殊含义的单个字符:
\d:单个数字字符 0-9
\w:单个单词字符a-zA-Z0-9_

1.  1.  量词符号:

?:表示出现0次或1次
:表示出现0次或多次
+:出现1次或多次
{
    
    m,n}:表示 m<= 数量 <= n
m如果缺省: {
    
    ,n}:最多n次
n如果缺省:{
    
    m,} 最少m次

1.  1.  开始结束符号
    
    *   ^:开始
    *   $:结束

Regular object:

  1. create
  2. var reg = new RegExp("Regular expression");
  3. var reg = /regular expression/;
  4. method
  5. test (parameter) Verifies whether the specified string conforms to the regular definition specification
    Form verification

Guess you like

Origin blog.csdn.net/weixin_43801418/article/details/113100316