Page 326 - Webapplication11_C11_Flipbook
P. 326
4.9 JAVASCRIPT SYNTAX AND RULES
JavaScript syntax refers to the rules and structure used to write JavaScript code. These rules govern how you must
format and write your code so that the browser or other JavaScript engines can properly interpret and execute it.
Below are some key elements and rules of JavaScript syntax:
Ð ÐCase Sensitivity: JavaScript is case-sensitive, means that myVariable and myvariable are treated as two different
variables. Keywords, variable names, function names, and identifiers must be used with the correct letter casing.
Ð ÐStatements: JavaScript programs are made up of statements, which are commands to be executed. Each statement
typically ends with a semicolon (;), although JavaScript can infer semicolons in many cases.
let x = 5;
let y = 6;
let z = x + y;
Ð ÐWhitespace: Extra spaces, tabs, and newlines are generally ignored in JavaScript code, which allows developers to
format code in a readable way.
For example, the following two blocks of code are treated the same:
let a = 5; let b = 6; let c = a + b;
let a = 5;
let b = 6;
let c = a + b;
Ð ÐComments: Comments are ignored by JavaScript engines and are used for documentation. Types of comments:
Single-line comments start with //:
// This is a single-line comment
let x = 5;
Multi-line comments are enclosed between /* and */:
/* This is a
multi-line comment */
let y = 10;
4.10 BASIC STRUCTURE OF A JAVASCRIPT PROGRAM
JavaScript cannot run on its own because it is a scripting language, and hence, needs to be embedded within an HTML
code. The basic structure of a JavaScript program is as follows:
<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY >
<SCRIPT TYPE="text/javascript">
...
Write JavaScript code here
...
...
</SCRIPT>
</BODY>
</HTML>
324 Touchpad Web Applications-XI

