javascript
javascript
// // Operators in JavaScript
// // 1=Arithmetic Operators
// // 2=Assignment Operators
// // 3=Comparison Operators
// // 4=Logical Operators
// // 5=Unary Operators
// // 6=Ternary Operator
// // 7=Bitwise Operators
// // 8=String Operators
// // 9=Type Operators
// // 10=Comma Operator
// // 1. Arithmetic Operators
// // These operators are used for basic mathematical calculations.
// // 2. Assignment Operators
// // These operators are used to assign values to variables and modify their
values.
// // = (Assign): Assigns a value to a variable.
// // Example:
// // let x = 5;
// // += (Add and Assign): Adds a value to the variable and assigns the
result.
// // Example:
// // x += 3; // x = x + 3
// // /= (Divide and Assign): Divides a value by the variable and assigns the
result.
// // Example:
// // x /= 2; // x = x / 2
// // %= (Modulus and Assign): Finds the remainder and assigns the result.
// // Example:
// // x %= 3; // x = x % 3
// // **= (Exponentiate and Assign): Raises the variable to the power and
assigns the result.
// // Example:
// // x **= 2; // x = x ** 2
// // 3. Comparison Operators
// // These operators compare two values and return true or false.
// // === (Strict Equal): Checks if two values are equal and of the same type.
// // Example:
// // 5 === "5" → false
// // !== (Strict Not Equal): Checks if two values are not equal or have
different types.
// // Example:
// // 5 !== "5" → true
// // > (Greater Than): Checks if the left value is greater than the right.
// // Example:
// // 7 > 5 → true
// // < (Less Than): Checks if the left value is less than the right.
// // Example:
// // 3 < 5 → true
// // >= (Greater Than or Equal): Checks if the left value is greater than or
equal to the right.
// // Example:
// // 7 >= 7 → true
// // <= (Less Than or Equal): Checks if the left value is less than or equal
to the right.
// // Example:
// // 4 <= 5 → true
// // 4. Logical Operators
// // These operators are used to combine boolean expressions.
// // 5. Unary Operators
// // These operators apply to a single operand.
// // ++ (Increment): Increases the operand's value by 1.
// // Example:
// // x++ (post-increment), ++x (pre-increment)
// // 6. Ternary Operator
// // A concise way to write an if-else statement.
// // 7. Bitwise Operators
// // These operators work on the binary form of numbers.
// // << (Left Shift): Shifts bits to the left by the specified number of
positions.
// // Example:
// // 5 << 1 → 10 (Binary: 0101 << 1 = 1010)
// // >> (Right Shift): Shifts bits to the right by the specified number of
positions.
// // Example:
// // 5 >> 1 → 2 (Binary: 0101 >> 1 = 0010)
// // >>> (Unsigned Right Shift): Shifts bits to the right, filling with 0
from the left.
// // Example:
// // -5 >>> 1 → 2147483642
// // 8. String Operators
// // These operators are used to manipulate strings.
// // 9. Type Operators
// // These operators check or determine the type of a value.
// // Unary operators:
// // ++ (Increment): Increases a variable's value by 1.
// // -- (Decrement): Decreases a variable's value by 1.
// // c++ = (post Increment) ; ++c = (pre Increment);
// // d-- = (post Decrement) ; --c = (pre Decrement);
// // */
// // // 1. Arithmetic Operators
// // let a = 5;
// // let b = 10;
// // // 2. Assignment Operators
// // let x = 5;
// // x += 3; // x = x + 3 -> 8
// // console.log("x += 3 →", x);
// // x -= 2; // x = x - 2 -> 6
// // console.log("x -= 2 →", x);
// // x *= 2; // x = x * 2 -> 12
// // console.log("x *= 2 →", x);
// // x /= 2; // x = x / 2 -> 6
// // console.log("x /= 2 →", x);
// // x %= 3; // x = x % 3 -> 0
// // console.log("x %= 3 →", x);
// // x **= 2; // x = x ** 2 -> 0
// // console.log("x **= 2 →", x);
// // // 3. Comparison Operators
// // console.log("5 == '5' →", 5 == '5'); // Output: true (Loose equality)
// // console.log("5 === '5' →", 5 === '5'); // Output: false (Strict
equality)
// // console.log("5 != '5' →", 5 != '5'); // Output: false (Loose inequality)
// // console.log("5 !== '5' →", 5 !== '5'); // Output: true (Strict
inequality)
// // console.log("7 > 5 →", 7 > 5); // Output: true (Greater than)
// // console.log("3 < 5 →", 3 < 5); // Output: true (Less than)
// // console.log("7 >= 7 →", 7 >= 7); // Output: true (Greater than or equal)
// // console.log("4 <= 5 →", 4 <= 5); // Output: true (Less than or equal)
// // // 4. Logical Operators
// // console.log("true && true →", true && true); // Output: true (AND)
// // console.log("true || false →", true || false); // Output: true (OR)
// // console.log("!true →", !true); // Output: false (NOT)
// // // 5. Unary Operators
// // let c = 5;
// // console.log("c++ →", c++); // Post-increment
// // console.log("++c →", ++c); // Pre-increment
// // let d = 10;
// // console.log("d-- →", d--); // Post-decrement
// // console.log("--d →", --d); // Pre-decrement
// // // 6. Ternary Operator
// // let age = 20;
// // console.log("age >= 18 ? 'Yes' : 'No' →", age >= 18 ? "Yes" : "No"); //
Output: Yes
// // // 7. Bitwise Operators
// // console.log("5 & 3 →", 5 & 3); // Output: 1 (Binary: 0101 & 0011 = 0001)
// // console.log("5 | 3 →", 5 | 3); // Output: 7 (Binary: 0101 | 0011 = 0111)
// // console.log("5 ^ 3 →", 5 ^ 3); // Output: 6 (Binary: 0101 ^ 0011 = 0110)
// // console.log("~5 →", ~5); // Output: -6 (Binary: ~0101 = 1010)
// // console.log("5 << 1 →", 5 << 1); // Output: 10 (Binary: 0101 << 1 =
1010)
// // console.log("5 >> 1 →", 5 >> 1); // Output: 2 (Binary: 0101 >> 1 = 0010)
// // console.log("-5 >>> 1 →", -5 >>> 1); // Output: 2147483642 (Unsigned
right shift)
// // // 8. String Operators
// // console.log('"Hello" + " World" →', "Hello" + " World"); // Output:
"Hello World"
// // let str = "Hello";
// // str += " World"; // Concatenation assignment
// // console.log("str += ' World' →", str); // Output: "Hello World"
// // // 9. Type Operators
// // console.log('typeof "Hello" →', typeof "Hello"); // Output: "string"
// // console.log('[] instanceof Array →', [] instanceof Array); // Output:
true
// // console.log('"Hello" instanceof String →', "Hello" instanceof String);
// Output: false
// // /arthmetic operator
// // let a = 5;
// // let b = 2;
// // console.log(a+b);
// // console.log(a-b);
// // console.log(a*b);
// // console.log(a/b);
// // console.log(a%b); //modulus
// // console.log(a**b); //Exponentiation
// // //unary operators
// // console.log(a++);
// // console.log(++a);
// // console.log(a--);
// // console.log(--a);
// // assigment operators
// // let a = 5;
// // let b = 5;
// // a = a+5;
// // a+=3;
// // a-=1;
// // comparison operators
// // let a =55;
// // let b=45;
// // console.log(a==b);
// // let name = prompt("enter your name")
// // let userName = "bakhtawar";
// // alert(name==userName);
// // let password = prompt("enter a password");
// // let savePassword ="pakistane123";
// // alert(password==savePassword);
// // let a = "bryan";
// // let b = "bryani";
// // console.log(a!=b);
// // let a = "65";
// // let b = 45;
// // console.log(a>=b);
// // logical oprators
// // let a = 8 ;
// // let b= 4;
// // let cond1 = a>b;
// // let cond2 = a===5;
// // console.log("cond1 && cond2 =", cond1 && cond2);
// // console.log("cond1 || cond2 =", cond1 || cond2);
// // console.log("cond1 ! cond2 =", !(a===8));
// // let age = prompt("Enter your age ");
// // if (age==20){
// // alert("you are eligble for vote ")}
// // else{
// // alert("you are not eligible")
// // }
// // }
// // if (num % 2 ===0){
// // alert(num + " is Even")
// // }
// // else {
// // alert(num + " is odd")
// // }
// // junior
// // senior
// // middle
// // }
// // else if(Grade>=70){
// // alert ("You Recived c Grade ")
// // }
// // else if (Grade>=50){
// // alert ("You Recived D Grade ")
// // }
// // else if (Grade>=40){
// // alert ("You Recived E Grade ")
// // }
// // else{
// // alert ("You are Fail ")
// // }
// alert ("10"==10);
// alert("10"===10);
// alert ("10"!=5);
// switch (item) {
// case "biryani":
// price = "Per plate Biryani Rs: 200";
// break;
// case "karahi":
// price = "Per plate Karahi Rs: 500";
// break;
// case "nihari":
// price = "Per plate Nihari Rs: 300";
// break;
// case "kabab":
// price = "Per plate Kabab Rs: 150";
// break;
// case "haleem":
// price = "Per plate Haleem Rs: 250";
// break;
// default:
// price = "No item available";
// }
// alert(price);