In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What are the programming specifications in JavaScript, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, hope you can gain something.
Background
JavaScript is a client-side scripting language that is used by Web projects. This guide lists the rules to follow when writing JavaScript.
JavaScript language specification variable
Var must be added to declare a variable
Keywords:
Var A1 = 1 * var b1 = 11
When you don't write var
Variables are exposed to the global context, which is likely to conflict with existing variables In addition, if not added, it is difficult to determine the scope of the variable, the variable is likely to be in the local scope, it is easy to leak into Document or Window, so be sure to use var
Variable.
Constant
Constant forms such as: NAMES_LIKE_THIS, even if you use uppercase characters and underscores, you can use the @ const tag to indicate that it is a constant, but do not use the const keyword.
For basic types of constants, you only need to convert the naming:
/ * The number of seconds of minute. * @ type {number} * / eflag.example.SECONDES_IN_A_MINUTE = 60
For non-basic types, use @ const
Tag:
/ * The number of seconds in each of the given units. * @ type {Object.} * @ const * / eflag.example.SECONDS_TABLE = {minute: 60 department hour: 60 * 60 department day: 60 * 60 * 24}
As for the keyword const, do not use it because IE is not recognized.
semicolon
Always use a semicolon. If you only rely on implicit segmentation between statements, it can be troublesome sometimes. Using a semicolon, you will know better where the statement begins and ends.
Semicolon at the end of line:
Var foo = 1) bar = 2) Baz = 3) obj = {foo: 1) bar: 2); single quotation marks ('') and double quotes ("")
Because JavaScript can recognize both single and double quotes as strings, in order to unify the specification, the definition of strings in JavaScript requires the use of single quotes:
Var val ='a'
Again, attributes in html use double quotes:
When dynamically generating html tags in JavaScript:
Var _ input =''; space
Five spaces between parameters and parentheses:
Function fn (arg1, arg2) {}
There is a space after the colon
{foo: 1,bar: 2,baz: 3}
Conditional statements have spaces
If (true) {} while (true) {} switch (v) {} Tips and TricksTrue and False Boolean expressions
The following Boolean expressions all return false:
Nullundefined'' empty string 0
The number 0 can be careful of the following, but all return true:
'0' string 0 [] empty array {} empty object
If you want to check whether the string is null or empty:
If (y! = null & & y! =') {}
It would be better to write like this:
If (y) {} conditional (ternary) operator (?:)
The ternary operator replaces the following code:
If (val! = 0) {return foo ();} else {return bar ();}
You can write as follows:
Return val? Foo (): bar ()
It is also useful when generating HTML code:
Var html =''; & & and | |
The binary Boolean operator can be short-circuited and the last term is calculated only when necessary. | | it is called the default operator, because it is possible to:
/ * * @ param {* =} opt_win * / function foo (opt_win) {var win; if (opt_win) {win = opt_win;} else {win = window;} / /.}
You can use it to simplify the above code:
/ * * @ param {* =} opt_win * / function foo (opt_win) {var win = opt_win | | window; /...} use join () to create a string
It is usually used like this:
Function listHtml (items) {var html ='
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.