I bought this book last year, but I haven’t read it yet. When I read it in my spare time, I found that the content is really good, so I decided to record some study notes on my blog, so that I can read and find it easily in the future.

  1. Js files are best placed in the < body> tag to make the browser load the page faster
  2. Statement
  • It is recommended to put a semicolon at the end of each statement to make the code easier to read. Making each statement a single line makes it easier to track the order in which JavaScript scripts are executed, such as
The first statement. The second statement.Copy the code

2.1 Comments

  • // Single-line comment
  • /* Multi-line comments */
  • , JavaScript does not require this, it will treat “– >” as part of the comment content, note: HTML allows the above
    spans multiple lines of comments, but JavaScript requires that each line of such comments be preceded by ”

2.2 Variable

  • The operation of storing a value is called assignment
mood = "happy";
age = "22";
Copy the code

When a variable is assigned a value, it is said to contain the word. The mood variable now contains the value “happy” and the age variable now contains 22

  • Note: JavaScript allows you to assign a value to a variable directly without declaring it beforehand. If JavaScript does not declare a variable before assigning it to it, the assignment will declare the variable automatically. While JavaScript does not enforce variables to be declared in advance, it is good programming practice to declare variables in advance.
  • A statement declares multiple variables at once and assigns values at once
var mood = "happy"; var age = "22"; Var mood = "happy",age = "22";Copy the code
  • In JavaScript, the names of variables and other syntactic elements are case sensitive.

    • JavaScript variable names do not allow variable names to contain Spaces or punctuation marks ($exception)
    • Letters, digits, dollar signs, and underscores are allowed (but the first character cannot be a number). To make variable names easier to read, you can insert underscores in appropriate places, such as
var my_mood = "happy";
Copy the code

An exception is to use the hump format, as in

var myMood = "mood";
Copy the code

Generally, the hump format is the preferred naming format for function names, method names, and object attribute names.