Home > Web Front-end > JS Tutorial > body text

Explanation of basic syntax and variables of JavaScript

亚连
Release: 2018-05-17 09:33:02
Original
1365 people have browsed it

Technical answers to the basic syntax of JavaScript and variables

1. Grammar

  • JavaScript is size-sensitive written.

  • Identifier refers to the name of a variable, function or attribute, or the parameter of a function. The following rules must be met:

              第一个字符必须是一个字母,下划线(_)或者一个美元符号($);
    
              其他字符可以是字母、下划线、美元符号、数字;
    
              按照惯例,采用驼峰命名的方式,就是第一个字母小写,剩下的每个有意义的单词首字母大写;
    
              不能把关键字、保留字、true、false、和null用作标识符;
    Copy after login
  • Comments

 //用双斜杠可以注释单行。
Copy after login
  /*
  *
 * 用斜杠、若干星号、斜杠以这种形式注释多行。 
 * 
  */
Copy after login
  • The statement ends with a semicolon.

    Adding a semicolon can avoid unnecessary trouble. In other words, adding a semicolon is not a rigid rule. When adding a semicolon to compress the code later, it improves the performance of the code because it does not require the system to Analyze where it ends and begins.

  • Use a code block, which can start with a left curly brace ({) and end with a right curly brace (}).

    2. Variables

  • ECMAScript variables are loosely typed, which means they can save any type of data.

  • Supports initializing variables. Assigning values ​​to undeclared variables in strict mode will throw a ReferenceError.

  • You can use one statement to define multiple variables, separated by commas, as in the following example:

var message="hi",
    found=false,
    lost=true,
    number=20;
Copy after login

The above is me I compiled it for everyone, I hope it will be helpful to everyone in the future.

Related articles:

Detailed explanation of the steps for PHP dynamic compression of js and css files

html css js drop-down list small triangle

How to avoid JS memory leaks in versions before IE9

The above is the detailed content of Explanation of basic syntax and variables of JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!