“A quantity that might change its value during execution of the program is called the variable”.
Amazon Purchase Links:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
|Variable name||Valid / Invalid||Reason for invalidity|
|Receipt#||Invalid||The special character # is not allowed|
|Plus-||Invalid||The special character hyphen (-) is not allowed|
var : it is keyword which is used to declare a variable.
Varname: it represents a valid variable name.
For example, to declare variables roll_no, name, and address, the statements are written as follows:
Assigning a value to a variable at time of its declaration is called initializing a variable.
Var variable = value;
Variable: specifies the name of variable to be initialized.
Value: specifies the value to be assigned to the variable.
For example, to declare a variable ‘x’ and to assign value 5 to it, the statement Is given below:
Var x= 5;
You can initialize a variable with a null value e.g.
Var x = null;
Let us see the following code:
Var y= 6;
Var z= x*y;
After execution of the above statements, the value 0 will be assigned to ‘z’.
Var x= 10;
Document.write(“value of x =” +x);
Output of code:
Value of x = 10
Number data type consists of numbers or numeric values. Mathematical calculations can be performed on number data type. Numeric values may be whole numbers or floating point numbers(i.e. real numbers)
Therefore, number data type is divided into two types:
An integer is a whole number without decimal part, it may have a positive or a negative value. the number 0,1,2,3….., and their negatives -1,-2,-3….., are examples of integers.
- A decimal (base 10) number based on 10 digits (from 0 to 9) such as 75802 is an example of decimal number. A decimal number never starts with a digit 0.
- Hexadecimal (base 16) number based on 16 digits that are from 0 to 9 and then from ‘A’ to ‘F’. the value of A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15. The number 2A6BF represents hexadecimal value.
- An octal (base 8) number base on 8 digits (from 0 to 10) such as 7502 is an example of octal number.
The number (or numeric values) that have decimal point in them are called floating point numbers. For example, 0.1, 0.002, 3.1010, 4.0 are floating point number. It must be noted that the 4.0 is floating point number while 4 is an integer number. The floating point number can also be represented in exponential notation. For example,
123.45 can be written as 0.12345×103
0.00012 can be written as 0.12×10-3
The number of digits after the decimal point is called precision. For example, in number 0.12345×103 , 103 the precision is 5. Similarly, in floating point number 0.12345×103 , 103 specifies the range of number.
The storage area occupied by the floating point number is divided into two section.
Mantissa : it is a value of the number.
Exponent: it is the value of exponential power.
For example, the number 6432157 can be represented as 6.432157 x 106, where 6.432157 is the mantissa and 6 is the exponent.
A String is just a sequence of characters treated s single data items, such as your name or address. You can say that a string data type consist of text. The mathematical operations cannot be performed on the string data type. The example of string type data are “012345”, “main road uk”, “john” etc.
for(n=1; n<=10; n++)
In the above script “n<=10” is a test condition and value 1 is assigned to variable ‘n’ before the loop statement to make the condition true. When the condition is nested, it will return true value, so body of loop will be executed. In the body of loop, the “n++”, statement changes the value of variable ‘n’ during program execution. After execution the body o loop 10 times, the value of ‘n’ becomes 11. So the loop is terminated and control shifts to the statement “document.write(“ok”); ” that comes immediately after the ‘while’ loop structure.