Comments
Comments can be used to document code. A comment is text that is not executed.
Types of Comment
1. Single-line comments start with two slashes (//). These comments can go on a line by themselves or they can go directly after a line of code.
// This is a single line comment.
let x = 1 // Here is another comment after a line of code.
2. Multi-line comments start with a slash and an asterisk (/*) and end with an asterisk and a slash (*/):
/* This is a comment which
spans multiple lines. */
3. Documentation comments (also known as "doc-strings" or "doc-comment") are a special set of commentsused to generate human-readable documentation, or provide documentation in an IDE. Doc-comments either start with three slashes (///) on each line, or are surrounded by /** and **/.
/// This is a documentation comment for `z`.
/// It spans multiple lines.
let z = 1. */
4. Nested comments
/* /* this */ is a valid comment */
Naming Convention
Names may start with any upper or lowercase letter (A-Z, a-z) or an underscore (_). This may be followed by zero or more upper and lower case letters, underscores, and numbers (0-9). Names may not begin with a number
// Valid: various valid name
PersonID _account _bal1
// Invalid: various invalid characters
!@#$%^&*
By convention, variables, constants, and functions have lowercase names; and types have title-case names.
Semicolons
Semicolons (;) are used as separators between declarations and statements.Semicolons must be used to separate multiple statements if they appear on the same line.
// Declare a constant and a variable on a single line, separated by semicolons.
let d = 1; var e = 2