Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write the comments and identifiers of JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:55:51 09月29日 Update

This article introduces the relevant knowledge of "how to write comments and identifiers of JavaScript". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

JavaScript comment

Not all JavaScript statements are executed.

The code between the double slash / / or / * and * / is considered a comment.

Comments are ignored and not executed:

Var x = 7; / / will execute

/ / var x = 8; will not execute

JavaScript identifier

The identifier is the name.

In JavaScript, identifiers are used to name variables (as well as keywords, functions, and tags).

In most programming languages, the rules for legal names are mostly the same.

In JavaScript, the first character must be a letter, an underscore (-), or a dollar sign ($).

A series of characters can be letters, numbers, underscores, or dollar signs.

Tip: the numeric value cannot be used as the first character. This way, JavaScript can easily distinguish between identifiers and numeric values.

JavaScript is case sensitive

All JavaScript identifiers are case sensitive.

The variables lastName and lastname are two different variables.

LastName = "Gates"

Lastname = "Jobs"

JavaScript does not translate VAR or Var into the keyword var.

JavaScript and hump case

Historically, programmers have used three ways to concatenate multiple words into a variable name:

Hyphen:

First-name, last-name, master-card, inter-city.

Note: hyphens cannot be used in JavaScript. It is reserved for subtraction.

Underline:

First_name, last_name, master_card, inter_city.

Hump case (Camel Case):

FirstName, LastName, MasterCard, InterCity.

CamelCase

JavaScript programmers tend to use hump capitalization that begins with lowercase letters:

FirstName, lastName, masterCard, interCity

This is the end of the content of "how to write the comments and identifiers of JavaScript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Identity identifier comment variable underscore size letter lowercase hump key keyword content name large numeric more knowledge program programmer symbol Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Huawei Shulou Information OPPO Reno