Page 73 - PortGPT_V2.1_C8_Flipbook
P. 73
For example:
var age = 16;
var name = "A"
We can declare multiple variables in the same line in the following way:
var v1 = 1, v2 = 'Delhi', v3;
Variable Naming Conventions
Some of the naming conventions that need to be followed while declaring variables in JavaScript are:
Variable names are case-sensitive which means that the variable name 'AGE' is different from
'age'.
A variable name must not start with digits 0–9.
Variable names can contain letters, digits, or the symbols $ and _.
A variable name cannot be a reserved keyword.
Operators
An operator is a symbol that is used to perform calculations on values or variables. The variables or
values on which the operator performs calculation are called operands. Some of the examples of
operators are + (Addition), - (Subtraction), * (Multiplication), / (Division), etc.
Expressions
An expression is a unit of code that is evaluated to a value. It is a combination of values and operators.
For example,
a = b + c;
Comments
A comment is used to add notes in your code or to disable sections of code without deleting them.
Comments are ignored by the JavaScript interpreter. There are two types of comments in JavaScript:
single line and multi line. Single line comments are added by using // and multi line comments are
added by using /* and */.
For example:
// alert("Hello"); Single line comment
/* a = 10;
b = 20; Multi line comment
*/
INPUT AND OUTPUT IN JAVASCRIPT
JavaScript allows us to take input from the user with the help of prompt( ) method. We can use the
prompt( ) method in the following way:
var age = prompt("Enter your age: ");
Introduction to JavaScript 71

