Java Script IT Notes
Java Script IT Notes
Don't have Telegram yet? Try it now! Click Here To Join Telegram Channels
➥ NEET_JEE ➲ @NEET_JEE_CET_QUIZ
➥ MHT-CET ➲ @MHT_CET_CHANNEL
➥ ★ @SCIENCECENTRALBOT ★
➥ ★ @NEET_JEE_CET_BOT
Variables in JavaScript
Variables are location in computer’s memory where values can be stored.
Variables are denoted with a symbol known as variable name. In JavaScript var
keyword is used to declare a variable.
E.g. var a;
a=40;
Q.4. What are the rules for naming a variable in JavaScript?
Rules for naming variables
Variable name must always begin with letter. It can include digits
It cannot contain any blank space or special symbol except underscore.
The length variable is limited upto 255 characters.
It cannot be reserved or standard keyword.
Multiple type of declaration is not allowed.
Variables name are case sensitive.
E.g. var first_name, b1234;
JavaScript support explicit as well as implicit declaration of variables.
Explicit declaration of variable
E.g. var a;
a = 25;
Implicit variable
a = 25;
E.g.
a=5; b=4;
z = ++a + b++; z = ++a + ++b;
z = 6 + 4 z= 6 + 5
z = 10 z = 11
Binary Operators
These operators operate on two variables
+ - Addition
- - Subtraction
* - Multiplication
/ - Division
% - Modulus - returns remainder of division
= - Assignment operator – assigns value of expression on the right hand
to the variable on left hand
Comparison Operator
Operator Description
== equal to
!= not equal
Example
var a=20, b=30, max;
max = (a> b) ? a : b;
Comments in JavaScript
They are non-executable statements in JS program. Comments are
of two types :
Single line comment --- using //
Multi line comment ---- using /* */
Q. Write JS program to input two numbers and display sum and product.
Q. Write JS program to input a number and find whether it is even no.
Selection Statements (Decision making statements)
1. if (condition)
It evaluates the condition expression. If it is TRUE, It executes the block of
code under it. If FALSE, it will not execute.
E.g. if(age>18)
{ document.write(“You are eligible for voting”);
2. if(condition) else
It evaluates the condition expression. If it is TRUE, it executes the block of
code under it. If FALSE, it will execute the block of code under else statement.
E.g. if(age>18)
{ document.write(“You are eligible for voting”);
}
else
{ document.write(“You are not eligible for voting”);
Syntax:
if(condition1)
{
Block1
}
else if(condition2)
{
Block2
}
else if(condition3)
{
Block3
}
else
{
Block4
4. switch … case
It is used to check variable or expression value with series of values and
execute the block under case statement.
Syntax:
switch (expression)
{
case value1 :
block1
case value2 :
block2
case value3 :
block3
default :
block4
}
Q. Write JS program to input day number of the week and display the day
in words. (E.g. Day number is 2 Output - Monday)
Looping Statements
They are used to execute a block of code certain number of times or until given
condition is true.
To create loop in JavaScript there are:
while() loop
do while() loop
for() loop
1. while loop
It executes a block of code until the condition given in it is TRUE.
Syntax:
while(condition)
{
code
var c=1;
while(c<=5)
{
document.write(“<br>Good Morning”);
c=c + 1;
}
var n=1;
while(n<=10)
{
document.write(“<br>” + n);
n=n+1;
}
</script>
LOOPS
while(c<=10)
{
document.write("<br>" + c);
c=c+1;
}
</script>
while(c<=50)
{
if(c%2 == 0)
{ document.write("<br>" + c); }
c=c+1;
}
</script>
while(c<=100)
{
if(c%4 == 0 && c%5==0)
{ document.write("<br>" + c); }
c=c+1;
}
</script>
2. do while () loop
In do while loop, the condition is checked at the end of the loop. So the loop
will run atleast once even if the condition is false.
E.g. <script>
var c=1;
while(c<0)
{
document.write("<br>" + c);
c = c + 1;
}
</script>
3. for( ) loop
for loop provides initialization, condition and update of counter variable in
the for header.
var c;
for( c=1; c<=10; c++)
{
document.write("<br>" + c);
}
</script>
}
</script>
var c, num;
}
</script>
Q.Ans.
What are the features of JavaScript?
What are the applications of JavaScript?
List the Unary, Binary, comparison and logical operators in
JavaScript.
Explain the two types of scripting.
List the different types of Assignment operators.
Explain the different literals in JavaScript.
Write the rules for naming variables in JavaScript.
Explain the if..else selection statement of JavaScript.
What is the use of loops? Give the structure of while loop.
Explain the data types in JavaScript
Explain the switch..case selection statement of JavaScript.
Click on any image to get study material & all notes
Don't have Telegram yet? Try it now! Click Here To Join Telegram Channels
➥ NEET_JEE ➲ @NEET_JEE_CET_QUIZ
➥ MHT-CET ➲ @MHT_CET_CHANNEL
➥ ★ @SCIENCECENTRALBOT ★
➥ ★ @NEET_JEE_CET_BOT