My first JS program

First, JS is more important. The formulation of ES standard is not based on any environment. It can provide better programming ability for all kinds of environment, and all kinds of environment can be its host environment.

The location in the browser environment where code is written

  1. Write directly inside a page-level script element
  2. It is recommended to use external script files to write JS code because of the separation of structure, behavior, and style. Easy to read and maintain code. This helps the browser cache JS files to reduce the number of interactions.
  • A page can have multiple script elements executed from top to bottom
  • If a script element is imported from outside the script, no code can be written inside the element, which will automatically ignore the code inside the element.
  • The script element has an optional attribute type with a value of text/script. This property is used to specify the type of code and is a MIME format. MIME media types (MIME types for short) are standardized names that describe the body content of a message entity (for example, text/ HTML, image/ JPEG).

The basic grammar

  • JS code is composed of multiple statements, each code should end with an English semicolon (not mandatory, general company development requirements to prevent errors, can also identify each sentence of JS code more accurately).
  • Grammar parts must be English symbols
  • JS is executed synchronously from top to bottom.
  • JS language is case sensitive

The input statement

All input statements are not standard for ES.

prompt(); Prompt the user for input

Output statements

None of the output statements are ES standard

  • document.write(); Print out content numbers on the page can be written directly, for Chinese characters and characters need to be printed in quotation marks. If a character is not quoted, it is treated as a variable.
// alert(personal header); Error or character double quote problem        alert("hello");
        document.write(1);
/ *        document.write(sfssg);
Document. write(yes yes yes);* / document.write("sgdsyty");  document.write("Comfortable");  console.log(2); Copy the code

  • alert(); pop-up
  • console.log(); Console output

annotation

Use by code readers does not participate in execution

  • Single-line comment // CTRL + /
  • Multi-line comments /* */ Alt + Shift + A Can change the shortcut CTRL + Shift + /

In vscode, Alt + shift + f can format code