WebPHP Unit21 - JS - PDF
WebPHP Unit21 - JS - PDF
Unit II
JS JavaScript is a client-side scripting language, which means the source code is processed by the
client's web browser rather than on the web server. It is lightweight and most commonly used
as a part of web pages. The JavaScript code can produce an error message before any
information is actually transmitted to the web server. It is an interpreted programming
language with object-oriented capabilities.
Operators Description
Arithmetic Operators used to perform mathematical operations between numeric operands.
Logical Operators used to combine two or more conditions.
Comparison Operators used to compare two operands and return boolean value true or false.
Assignment Operators used to assign values to variables with less key strokes.
Bitwise Operators used to perform bitwise operations on operands.
Special Operators used to perform special operations.
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
NSS College Rajakumari, Dept. of Computer Applications 8
Web Programming using PHP
Unit II Bitwise Operators
JS Operator Name Description Example
& AND Sets each bit to 1 if both bits are 1 5&1=1
| OR Sets each bit to 1 if one of two bits is 1 5|1=5
^ XOR Sets each bit to 1 if only one of two bits is 1 5 ^1=4 More
~ NOT Inverts all the bits ~5 = -6
<< Zero fill left shift Shifts left by pushing zeros in from the right and let the leftmost bits fall off 5 << 1 = 10
(Sign preserving) Shifts right by pushing copies of the leftmost bit in from the
>> Signed right shift -5 >> 1 = -3
left, and let the rightmost bits fall off
>>> Zero fill right shift Shifts right by pushing zeros in from the left, and let the rightmost bits fall off 5 >>> 1 = 2
Special Operators
Operator Description Operator Description
Conditional Operator returns value based on the new creates an instance (object)
(?:)
condition. It is like if-else. typeof checks the type of object.
Comma Operator allows multiple expressions to be void it discards the expression's return value.
,
evaluated as single statement.
checks what is returned in a generator by the generator's
delete Delete Operator deletes a property from the object. yield
iterator.
in In Operator checks if object has the given property
instanceof checks if the object is an instance of given type
NSS College Rajakumari, Dept. of Computer Applications 9
Web Programming using PHP
Unit II JavaScript – Operators Example
JS
References
1. https://www.tutorialspoint.com
2. https://www.geeksforgeeks.org
3. https://www.w3schools.com
4. https://www.javapoint.com
5. https://developer.mozilla.org
6. https://techterms.com
7. https://www.tutorialsteacher.com
8. https://www.c-sharpcorner.com
9. Background vector created by grmarc - www.freepik.com
https://www.freepik.com/free-photos-
vectors/background