javascript 词汇_JavaScript的词汇结构

javascript 词汇

统一码 (Unicode)

JavaScript is written in Unicode. This means you can use Emojis as variable names, but more importantly, you can write identifiers in any language, for example Japanese or Chinese, with some rules.

JavaScriptUnicode编写。 这意味着您可以将Emojis用作变量名,但更重要的是,您可以使用某些规则以任何语言(例如日语或中文)编写标识符。

分号 (Semicolons)

JavaScript has a very C-like syntax, and you might see lots of code samples that feature semicolons at the end of each line.

JavaScript具有非常类似于C的语法,并且您可能会在每一行的末尾看到很多带有分号的代码示例。

Semicolons aren’t mandatory, and JavaScript does not have any problem in code that does not use them, and lately many developers, especially those coming from languages that do not have semicolons, started avoiding using them.

分号不是强制性的 ,并且JavaScript在不使用分号的代码中也没有任何问题,最近,许多开发人员,尤其是来自那些没有分号的语言的开发人员,开始避免使用它们。

You just need to avoid doing strange things like typing statements on multiple lines

您只需要避免做奇怪的事情,例如在多行上键入语句

return
variable

or starting a line with parentheses ([ or () and you’ll be safe 99.9% of the times (and your linter will warn you).

或以括号开头( [( ))开始,您将有99.9%的时间是安全的(您的短毛猫会警告您)。

It goes to personal preference, and lately I have decided to never add useless semicolons, so on this site you’ll never see them.

这取决于个人喜好,最近我决定不再添加无用的分号 ,因此在此站点上您永远不会看到它们。

空格 (White space)

JavaScript does not consider white space meaningful. Spaces and line breaks can be added in any fashion you might like, even though this is in theory.

JavaScript认为空白没有意义。 即使从理论上讲 ,空格和换行符也可以按照您喜欢的任何方式添加。

In practice, you will most likely keep a well defined style and adhere to what people commonly use, and enforce this using a linter or a style tool such as Prettier.

在实践中,您很可能会保持明确的样式并遵守人们常用的样式,并使用短绒棉布或样式工具(例如Prettier)来强制实施。

For example I like to always 2 characters to indent.

例如,我喜欢总是2个字符缩进。

区分大小写 (Case sensitive)

JavaScript is case sensitive. A variable named something is different from Something.

JavaScript区分大小写。 名为something的变量不同于Something

The same goes for any identifier.

任何标识符也是如此。

注释 (Comments)

You can use two kind of comments in JavaScript:

您可以在JavaScript中使用两种注释:

/* */

//

The first can span over multiple lines and needs to be closed.

第一个可以跨越多行,需要关闭。

The second comments everything that’s on its right, on the current line.

第二行注释当前行右边的所有内容。

文字和标识符 (Literals and Identifiers)

We define as literal a value that is written in the source code, for example a number, a string, a boolean or also more advanced constructs, like Object Literals or Array Literals:

我们将在源代码中写入的值定义为文字 ,例如数字,字符串,布尔值或其他更高级的构造,例如对象文字或数组文字:

5
'Test'
true
['a', 'b']
{color: 'red', shape: 'Rectangle'}

An identifier is a sequence of characters that can be used to identify a variable, a function, an object. It can start with a letter, the dollar sign $ or an underscore _, and it can contain digits. Using Unicode, a letter can be any allowed char, for example an emoji 😄.

标识符是一系列字符,可用于识别变量,函数,对象。 它可以以字母,美元符号$或下划线_开头,并且可以包含数字。 使用Unicode,字母可以是任何允许的字符,例如emoji😄。

Test
test
TEST
_test
Test1
$test

The dollar sign is commonly used to reference DOM elements.

美元符号通常用于引用DOM元素。

保留字 (Reserved words)

You can’t use as identifiers any of the following words:

您不能将以下任何单词用作标识符:

break
do
instanceof
typeof
case
else
new
var
catch
finally
return
void
continue
for
switch
while
debugger
function
this
with
default
if
throw
delete
in
try
class
enum
extends
super
const
export
import
implements
let
private
public
interface
package
protected
static
yield

because they are reserved by the language.

因为它们是语言所保留的。

翻译自: https://flaviocopes.com/javascript-lexical-structure/

javascript 词汇

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值