- JavaScript does not enforce the requirement to add at the end of each statement
;
, and the engine responsible for executing JavaScript code in the browser automatically complements the end of each statement ;
.
- JavaScript is strictly case sensitive
- The type of variable itself is called Dynamic language, and it corresponds to static language. Static languages must specify the variable type when defining the variable, and if the type does not match, an error is given. For example, Java is a static language and JavaScript is a dynamic language.
- If a variable is used without a
var
declaration, the variable is automatically declared as a global variable. In different JavaScript files on the same page, if you do not have var
to declare it, the variables i
will be used, causing i
the variables to interact with each other, resulting in hard-to-debug error results.
- JavaScript code that runs in strict mode, which is enforced by
var
declaring variables that are var
used without declaring variables, will result in run errors. The way to enable strict mode is to write on the first line of the JavaScript code:‘use strict‘;
- Browsers that do not support strict mode will execute it as a string statement, and browsers that support strict mode will turn on strict mode to run JavaScript. Variables that are not
var
declared are considered global variables, and in order to avoid this flaw, all JavaScript code should use the strict pattern.
- Multi-line string: Because the multiline string is more
\n
cumbersome to write, the newest ES6 standard adds a multi-line string representation, using ' ... ' means
- Template string: If there are many variables that need to be connected,
+
it is more troublesome to use the number. ES6 adds a template string that represents the same method as the multiline string above, but it automatically replaces the variables in the string:var message = `你好, ${name}, 你今年${age}岁了!`;
The string is immutable, and if you assign a value to an index of a string, there is no error, but there is no effect:
var s = ‘Test‘;s[0] = ‘X‘;alert(s); // s仍然为‘Test‘
JavaScript Learning notes