Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

JAVA SCRIPT STUDY NOTES, Study notes of Javascript programming

The concept of global variables in JavaScript, how to declare them within and outside functions, and how to access them. It also covers the different data types in JavaScript, including primitive and non-primitive types, and provides examples of each. Additionally, the document discusses bitwise, logical, assignment, and special operators in JavaScript, and provides examples of each. Finally, the document explains the if-else statement in JavaScript and provides examples of its different forms.

Typology: Study notes

2022/2023

Available from 01/03/2023

PRAKASH09
PRAKASH09 🇮🇳

2 documents

1 / 14

Toggle sidebar

Related documents


Partial preview of the text

Download JAVA SCRIPT STUDY NOTES and more Study notes Javascript programming in PDF only on Docsity! avaScript Global Variable A JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function. Let’s see the simple example of global variable in JavaScript. 1. <script>   2. var value=50;//global variable   3. function a(){   4. alert(value);   5. }   6. function b(){   7. alert(value);   8. }   9. </script>   Test it Now Declaring JavaScript global variable within function To declare JavaScript global variables inside function, you need to use window object. For example: 1. window.value=90;   Now it can be declared inside any function and can be accessed from any function. For example: 1. function m(){   2. window.value=100;//declaring global variable by window object   3. }   4. function n(){   5. alert(window.value);//accessing global variable from other function   6. }   Test it Now Internals of global variable in JavaScript When you declare a variable outside the function, it is added in the window object internally. You can access it through window object also. For example: 1. var value=50;   2. function a(){   3. alert(window.value);//accessing global variable    4. }   Javascript Data Types JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript. 1. Primitive data type 2. Non-primitive (reference) data type JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc. For example: 1. var a=40;//holding number   2. var b="Rahul";//holding string   JavaScript primitive data types There are five types of primitive data types in JavaScript. They are as follows: Data Type Description String represents sequence of characters e.g. "hello" Number represents numeric values e.g. 100 Boolean represents boolean value either false or true Undefined represents undefined value Null represents null i.e. no value at all > Greater than >= Greater than or equal to < Less than <= Less than or equal to JavaScript Bitwise Operators The bitwise operators perform bitwise operations on operands. The bitwise operators are as follows: Operator Description Example & Bitwise AND (10==20 & 20==33) = false | Bitwise OR (10==20 | 20==33) = false ^ Bitwise XOR (10==20 ^ 20==33) = false ~ Bitwise NOT (~10) = -10 << Bitwise Left Shift (10<<2) = 40 >> Bitwise Right Shift (10>>2) = 2 >>> Bitwise Right Shift with Zero (10>>>2) = 2 JavaScript Logical Operators The following operators are known as JavaScript logical operators. Operator Description Example && Logical AND (10==20 && 20==33) = false || Logical OR (10==20 || 20==33) = false ! Logical Not !(10==20) = true JavaScript Assignment Operators The following operators are known as JavaScript assignment operators. Operator Description Example = Assign 10+10 = 20 += Add and assign var a=10; a+=20; Now a = 30 -= Subtract and assign var a=20; a-=10; Now a = 10 *= Multiply and assign var a=10; a*=20; Now a = 200 /= Divide and assign var a=10; a/=2; Now a = 5 %= Modulus and assign var a=10; a%=2; Now a = 0 JavaScript Special Operators The following operators are known as JavaScript special operators. Operator Description (?:) Conditional Operator returns value based on the condition. It is like if-else. , Comma Operator allows multiple expressions to be evaluated as single statement. delete Delete Operator deletes a property from the object. in In Operator checks if object has the given property instanceof checks if the object is an instance of given type new creates an instance (object) typeof checks the type of object. void it discards the expression's return value. yield checks what is returned in a generator by the generator's iterator. JavaScript If-else The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript. 1. If Statement 2. If else statement 3. if else if statement JavaScript If statement It evaluates the content only if expression is true. The signature of JavaScript if statement is given below. 1. if(expression){   2. //content to be evaluated   3. }   Flowchart of JavaScript If statement 4. document.write("a is even number");   5. }   6. else{   7. document.write("a is odd number");   8. }   9. </script>   JavaScript If-else The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript. 1. If Statement 2. If else statement 3. if else if statement JavaScript If statement It evaluates the content only if expression is true. The signature of JavaScript if statement is given below. 1. if(expression){   2. //content to be evaluated   3. }   Flowchart of JavaScript If statement Let’s see the simple example of if statement in javascript. 1. <script>   2. var a=20;   3. if(a>10){   4. document.write("value of a is greater than 10");   5. }   6. </script>   Test it Now Output of the above example value of a is greater than 10 JavaScript If...else Statement It evaluates the content whether condition is true of false. The syntax of JavaScript if-else statement is given below. 1. if(expression){   2. //content to be evaluated if condition is true   3. }   4. else{   5. //content to be evaluated if condition is false   6. }  
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved