[Go to site: main page, start]

0% found this document useful (0 votes)
33 views17 pages

12th Science JavaScript Study Notes

The document provides comprehensive study material on JavaScript, covering its features, applications, data types, operators, and control structures such as loops and selection statements. It includes examples and explanations of variable declaration, types of scripting, and various operators. Additionally, it offers resources for further study through Telegram channels and bots for accessing notes and materials related to 11th and 12th-grade science topics.

Uploaded by

swayammallah2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views17 pages

12th Science JavaScript Study Notes

The document provides comprehensive study material on JavaScript, covering its features, applications, data types, operators, and control structures such as loops and selection statements. It includes examples and explanations of variable declaration, types of scripting, and various operators. Additionally, it offers resources for further study through Telegram channels and bots for accessing notes and materials related to 11th and 12th-grade science topics.

Uploaded by

swayammallah2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Click on any image to get study material & all notes

Don't have Telegram yet? Try it now! Click Here To Join Telegram Channels

JOIN TELEGRAM ➭ @NEET_JEE_CET_QUIZ

JOIN TELEGRAM ➭@MHT_CET_EXAM_NOTES

12Th Science Notes Maharashtra Board


16 769 subscribers
27
05 HERE YOU GET ALL 11TH & 12TH STUDY MATERIAL

➥ NEET_JEE ➲ @NEET_JEE_CET_QUIZ

➥ MHT-CET ➲ @MHT_CET_CHANNEL

➥ USE BOT FOR ALL NOTES 01F


4DD

➥ ★ @SCIENCECENTRALBOT ★
➥ ★ @NEET_JEE_CET_BOT

⚠For more info.. [Link]


View in Telegram
Preview channel
If you have Telegram, you can view and join
12Th Science Notes Maharashtra Board right away.

Click Here To Join Telegram Channels

JOIN TELEGRAM ➭ @NEET_JEE_CET_QUIZ


JAVASCRIPT
JavaScript is an object oriented scripting language used in web pages.
It is an interpreted language.
It was developed by Brendan Eich at Netscape Communications in 1996.
JavaScript was first supported by Netscape Navigator Browser.
Q. 1. Explain features of JavaScript
Ans. Page No. 200
Q. 2. Give the applications of JavaScript.
Ans. Page No. 200 and 201
Q.3. Explain the two types of scripting.
Ans. Client Side Scripting - The scripts that are written to run on the web-site
visitor’s computer and browser are known as client side scripts. They are mainly
used for adding special effects, validating input data, change web page data, etc..
E.g. JavaScript, VBScript, Jscript, JQuery, Angular JS, etc..
Server Side Scripting - The scripts are executed on the Server and the output
generated is sent in HTML format to client . E.g. ASP, JSP, PHP

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;

Q.5. Explain the data types in JavaScript.


Data types of Variables
Each variable used in JavaScript belong to a specific data type.
The following are Primitive data types in JavaScript :
1) Number - contains whole number or decimal number
2) String - contains series of characters in quotation marks
3) Boolean - contains TRUE or FALSE values
4) Undefined - a variable without value is undefined
The data type of the variable can be displayed using typeof operator.

Q.6. Explain the different operators in JavaScript.


Operators
Unary Operators - they operate on single variable
++ - increases the value by 1
-- - decreases the value by 1
E.g. var a;
a = 25;
a++;
--a;
++a - Pre-increment operator
a++ - Post increment operator
--a - Pre-decrement operator
a-- - Post decrement operator

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

Composite assignment operator


+= Composite Addition operator
-=
*=
/=
%=

E.g. a+=2; means a=a+2;


<script>
var a, b, z;
a=5;
b=4;
[Link](" Value of a is " + a);
[Link]("<br> Value of b is " + b);
a+=3; // means a = a + 3
b*=2; // means b = b * 2
z = a%b; // means a/b take remainder as answer
[Link]("<br>Value of a is " + a);
[Link]("<br>Value of b is " + b);
[Link]("<br>Value of z is " + z);
</script>

Comparison Operator
Operator Description

== equal to

=== equal value and equal type

!= not equal

!== not equal value or not equal type

> greater than


< less than
>= greater than or equal to
<= less than or equal to
Logical Operators
Operator Description Example
&& and (x < 10 && y > 1) is true
|| or (x == 5 || y == 5) is false
! not !(x == y) is true
Conditional (Ternary) Operator
JavaScript also contains a conditional operator that assigns a value to a variable
based on some condition.
Syntax
variablename = (condition) ? value1:value2

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)
{ [Link](“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)
{ [Link](“You are eligible for voting”);

}
else
{ [Link](“You are not eligible for voting”);

Q. Write JS program to input age display whether eligible for voting.

3. if(condition) else if(condition) …. ladder


It is used to check value with multiple conditions. It is used to test a
sequence of parallel alternatives.

Syntax:
if(condition1)
{
Block1
}

else if(condition2)
{
Block2
}
else if(condition3)
{
Block3
}

else
{
Block4

Q. Write JS Program to input percentage and display grade.

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)

Q. Write JS Program to input rollno, name, marks in any three subjects.


Find GTotal, Percentage and Grade.

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

Q. Write JS program to print Good Morning 5 times.


E.g.
C
<script>
6

var c=1;

while(c<=5)
{
[Link](“<br>Good Morning”);
c=c + 1;
}

[Link](“<br> Loop completed”);


</script>

Q. Write JS program to display numbers from 1 to 10.


<script>

var n=1;

[Link](“<h2>Display numbers from 1 to 10</h2>”);

while(n<=10)
{
[Link](“<br>” + n);
n=n+1;
}
</script>
LOOPS

To execute a block of code number of times until condition is true.

E.g. To display numbers from 1 to 10


<script>
var c;
c=1;

while(c<=10)
{

[Link]("<br>" + c);
c=c+1;
}
</script>

Q. Display even numbers from 1 to 50


<script>
var c;
c=1;

while(c<=50)
{
if(c%2 == 0)
{ [Link]("<br>" + c); }

c=c+1;
}
</script>

Q. Display numbers from 1 to 100 which are multiples of 4 and 5


<script>
var c;
c=1;

while(c<=100)
{
if(c%4 == 0 && c%5==0)
{ [Link]("<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)
{
[Link]("<br>" + c);
c = c + 1;
}
</script>

3. for( ) loop
for loop provides initialization, condition and update of counter variable in
the for header.

E.g. Display numbers from 1 to 10


<script>

var c;
for( c=1; c<=10; c++)
{

[Link]("<br>" + c);
}
</script>

Q. Write JS program to print numbers from 1 to 100 which are divisible by


3, 5 and 9 using for loop.
<script>
var c;
for( c=1; c<=100; c++)
{
if( )
{ [Link]("<br>" + c); }

}
</script>

Q. Write JS program to print multiplication table of a number entered,


using for loop.
<script>

var c, num;

num = parseInt(prompt("Enter a number"));

[Link](" <h2> Multiplication Table</h2>");


for(c=1; c<=10;c++)
{

[Link]("<br>" + num + " x " + c + " = " + num*c);

}
</script>
[Link].
 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

JOIN TELEGRAM ➭ @NEET_JEE_CET_QUIZ

JOIN TELEGRAM ➭@MHT_CET_EXAM_NOTES

12Th Science Notes Maharashtra Board


16 769 subscribers
27
05 HERE YOU GET ALL 11TH & 12TH STUDY MATERIAL

➥ NEET_JEE ➲ @NEET_JEE_CET_QUIZ

➥ MHT-CET ➲ @MHT_CET_CHANNEL

➥ USE BOT FOR ALL NOTES 01F


4DD

➥ ★ @SCIENCECENTRALBOT ★
➥ ★ @NEET_JEE_CET_BOT

⚠For more info.. [Link]


View in Telegram
Preview channel
If you have Telegram, you can view and join
12Th Science Notes Maharashtra Board right away.

Click Here To Join Telegram Channels

JOIN TELEGRAM ➭ @NEET_JEE_CET_QUIZ

Common questions

Powered by AI

In JavaScript, selection statements such as 'if-else' are used for decision-making by executing different blocks of code based on Boolean condition evaluation. The structure of an 'if-else' statement includes a condition evaluated by the 'if' keyword. If the condition is true, the code block immediately following the 'if' is executed . If the condition is false, and there is an 'else' clause, the code block within the 'else' section runs instead . This mechanism allows for decision control within the program, enabling different operations based on variable states or inputs .

Loops in JavaScript facilitate the repeated execution of a block of code as long as a specified condition is true. The 'for' loop is ideal for iterating a specified number of times, with initialization, condition, and increment specified in the loop header . For example, 'for(var c=1; c<=10; c++) { document.write("<br>" + c); }' displays numbers from 1 to 10 . The 'while' loop continues executing a block as long as its condition remains true, evaluated before each iteration . 'do-while' loops execute the contained block once before checking the condition , for instance, 'do { document.write("<br>" + c); } while(c<0);', guaranteeing at least one iteration .

The 'switch-case' statement in JavaScript provides a streamlined approach to handling multiple conditional operations by evaluating an expression against multiple case values rather than using multiple 'if-else' statements. It enhances code readability and maintainability when dealing with multiple conditions . The 'switch' statement begins execution by evaluating the expression; the control transfers to the matching 'case' block, executing its contained statements until a 'break' is encountered . If no case matches, the 'default' block executes, providing a catch-all for unmatched conditions. This construct simplifies complex decision chains, allowing for efficient categorization and execution of tasks based on distinct values .

Variable naming in JavaScript is governed by specific rules to ensure consistent and error-free code. Names must begin with a letter, can include digits or underscores, and should not contain spaces or special symbols besides the underscore . JavaScript variable names are case-sensitive and cannot use reserved words or standard keywords . Ensuring adherence to these rules, such as maintaining clear and descriptive names and avoiding ambiguous identifiers, encourages consistency and reduces the potential for conflicts and errors, thereby enhancing code maintainability and readability .

Comments in JavaScript serve as non-executable annotations that provide utility for developers by improving code readability, making it easier to understand the purpose and functionality of code blocks. They are also used for debugging by temporarily disabling code execution. JavaScript supports two types of comment syntax: single-line comments using '//' and multi-line comments enclosed within '/*...*/' . These comments help document the code, making it easier for developers to collaborate, revisit, or refactor code without misinterpretation .

The primary types of scripting in web development are client-side scripting and server-side scripting. Client-side scripting runs on the web-site visitor's browser and is used to create effects, validate data, and modify page content; examples include JavaScript, VBScript, Jscript, JQuery, and AngularJS . Server-side scripting runs on the server and generates HTML to be sent to the client; examples include ASP, JSP, and PHP .

Operators in JavaScript, such as unary, binary, comparison, and logical operators, play critical roles in expression evaluation and flow control. Unary operators work with a single operand, like '++' for increment and '--' for decrement . Binary operators deal with two operands and include arithmetic operators like '+', '-', '*', '/', and '%' for modulus . Comparison operators, such as '==', '!=', '>', '<', are used to compare values and affect flow control by determining conditions in control statements . Logical operators like '&&' (and), '||' (or), and '!' (not) enable compound conditions and are crucial in decision-making processes within code . These operators control the flow of execution in if-else and loop constructs by deciding the course of actions based on evaluated conditions .

Primitive data types in JavaScript include Number, String, Boolean, and Undefined . The 'typeof' operator is used to ascertain the data type of a variable or operand in JavaScript, providing a clear means to handle variables appropriately according to their type. For instance, it can be used to determine if a variable holds a numerical value or if it is undefined . This is crucial in ensuring accurate data processing and avoiding errors that could arise from incorrect type operations .

Composite assignment operators in JavaScript combine arithmetic operations with assignment, simplifying code writing and enhancing readability by reducing redundancy. They allow operations and assignment in a single step. For example, 'a += 2' increments the value of 'a' by 2, equivalent to 'a = a + 2' . Other examples include '-=' for subtraction, '*=' for multiplication, '/=' for division, and '%=' for modulus . These operators reduce the need for repeated variable names, making the code more concise and reducing potential errors in expressions .

In JavaScript, the 'var' keyword is used to declare variables, which can influence the variable's scope and hoisting behavior. 'var' variables are globally scoped if declared outside a function, and function-scoped if declared within one . These variables are also subjected to hoisting, meaning the variable declaration is moved to the top of its scope, allowing the variable to be used before it is declared without causing a runtime error . However, only the declaration is hoisted, not the initialization. This means the variable will have 'undefined' value before the line where it is initialized if accessed .

You might also like