Home > Article > Web Front-end > Explanation of basic syntax and variables of JavaScript
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用作标识符;
Comments
//用双斜杠可以注释单行。
/* * * 用斜杠、若干星号、斜杠以这种形式注释多行。 * */
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;
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!