Variables are a mechanism to store values in a program. Line 1 declares a variable by the name message. Let us start with the traditional “Hello World” example". Multi-line comments (/* */) − These comments may span multiple lines. Single-line comments (//) − Any text between a // and the end of a line is treated as a comment. JavaScript supports the following types of comments − Comments can be used to include additional information about a program like the author of the code, hints about a function/construct, etc. Comments in JavaScriptĬomments are a way to improve the readability of a program. However, these statements must be separated by a semicolon. ![]() ExampleĪ single line can contain multiple statements. Semicolons are OptionalĮach line of instruction is called a statement. This means that JavaScript differentiates between the uppercase and the lowercase characters. You can use spaces, tabs, and newlines freely in your program and you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand. Examples of valid identifiersĮS6 ignores spaces, tabs, and newlines that appear in programs. The following table illustrates some valid and invalid identifiers. ![]() Identifiers cannot include special symbols except for underscore (_) or a dollar sign ($). However, the identifier cannot begin with a digit. Identifiers can include both, characters and digits. Identifiers − These are the names given to elements in a program like variables, functions, etc. These are ignored by the JavaScript engine. Modules − Represents code blocks that can be reused across different programs/scripts.Ĭomments − Used to improve code readability. Some commonly used keywords are listed in the following table. The following table lists some keywords in JavaScript. Keywords − Words that have a special meaning in the context of a language. Operators − Symbols that define how the operands will be processed. Literals − Represents constant/fixed values. Variables − Represents a named memory block that can store values for the program. Every language specification defines its own syntax.Ī JavaScript program can be composed of − ![]() Syntax defines the set of rules for writing programs.
0 Comments
Leave a Reply. |