Basic Structure of JavaScript Programming
Photo By Tim Gouw on Unsplash
In this article, we will discuss the basic structure of JavaScript programming. The points covered include: Syntax, Statements, Unicode, Semicolons, White Space, Case Sensitivity, Comments, Literals, Identifiers, and Reserved Words.
Every programming language has its own syntax, and each language has different syntax rules. Syntax refers to the set of rules for writing commands in programming. A program or application consists of commands written according to the rules of a specific programming language.
Statement in Javascript
A statement is an instruction or command that executes a program, written following the syntax rules of the programming language. In JavaScript, common types of statements include control statements, loop statements, function statements, class statements, and exception handling statements.
Unicode
JavaScript allows the use of Unicode characters, including emojis. For example, a programmer can use an emoji as an identifier in a variable. Additionally, programmers can write identifiers using Latin, Chinese, or Japanese characters. However, this usage must follow the specified rules.
Semicolons in JavaScript
The use of semicolons in JavaScript is optional. In this tutorial, I do not use semicolons at the end of statements. For more details, please read my article on Semicolons.
White Space
In theory, JavaScript ignores spaces, tabs, and new lines. This allows programmers to write code freely in their preferred style.
Additionally, it helps with code indentation. For example, I use an indentation of 2 spaces to make the code more readable.
Case Sensitivity
JavaScript syntax is case-sensitive, meaning it distinguishes between uppercase and lowercase letters. For example, Function is different from function because the first one starts with an uppercase letter while the second starts with a lowercase letter.
Comments
Comments in JavaScript can be written using double slashes (//) for single-line comments. To write multi-line comments, use /* to start and */ to end the comment.
Comments in JavaScript prevent code from being executed. They are typically used to provide explanations before executing code. For more detailed explanations, you can read the following article Comments in JavaScript.
Literals
Literals can be easily understood as values, such as numbers or strings. Advanced constructs include object data types like arrays, objects, and functions.
Identifiers
An identifier is the name assigned to a variable. Identifiers bind a value using an equal sign (=). There are specific rules for identifiers, which you can find in the article Variables – Using var, let, and const.
Reserved Words
JavaScript has special keywords that cannot be used as function names or variable identifiers.
Some of these reserved words include : 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.
That’s the explanation of Basic Structure of JavaScript Programming that Mangcoding can share. Hopefully, this article is useful and provides new insights for you. If you have constructive feedback or suggestions, feel free to leave a comment or contact us via email and Mangcoding’s social media.
Source : Muhammadiqbal