Summary of "Advanced JavaScript Programming"

1. Basic concepts of JS

1. Naming rules

    • Variable names are case-sensitive (test and Test are two different variable names), and identifiers are named in camel case, that is: the first letter is lowercase, and the first letter of each remaining meaningful word is uppercase;
    • The first character of the identifier must start with a letter, _, $;
    • Identifiers and variable names cannot be the same as keyword reserved words;
    • Other characters can be numbers, letters, underscores, or $.

2. Notes

  • // single line comment
  • /**/ Multi-line comment

3. Strict Mode

Browsers that support strict mode are: IE10+, Firefox 4+, Safari 5.1+, Opera 12+, and Chrome.

Use "use strict"; at the top to tell JS-enabled engines to switch to strict mode. It is also possible to specify a function in a method to execute in strict mode.

ex: function doSomething(){

    "use strict";

     // function body

  }

4. Variables

Use the var operator to define variables, ex:var message; here defines a message variable

Global variables are defined outside the method or do not write var (inside and outside the method). This is generally not recommended because global variables defined without var are difficult to maintain and will not be defined immediately, causing confusion.

var message,found=flase,age=21,name="zhangsan";You can separate variables with commas in one sentence and define multiple energies at the same time, which can be initialized or not.

5. Data type

Undefined、Null、Boolean、Number、String

Use the typeof operator to detect the data type of the given variable, and the return value is as follows:

undefined - the value is undefined

boolean - the value is a boolean

String - the value is a string

number - the value is a numeric type

object - the value is an object or null

function - the value is a function

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325008453&siteId=291194637