Posted January 23Jan 23 You are reading Part 3 of the 39-part series: JavaScript Skill Progression: The Path from Beginner to Extreme. [Level 1]IntroductionOperators and expressions form the backbone of JavaScript, allowing developers to perform calculations, compare values, and control logic. JavaScript provides various types of operators, including arithmetic, comparison, logical, and assignment operators. Understanding how these work is essential for writing efficient and effective code.Operators and expressions are vital components of JavaScript, allowing developers to perform calculations, make decisions, and control program flow. Mastering arithmetic, comparison, logical, and assignment operators will enable you to write more effective and efficient JavaScript code.Arithmetic OperatorsArithmetic operators perform mathematical calculations on numeric values.OperatorDescriptionExample+Additionlet sum = 5 + 3; // 8-Subtractionlet difference = 10 - 4; // 6*Multiplicationlet product = 6 * 3; // 18/Divisionlet quotient = 12 / 4; // 3%Modulus (Remainder)let remainder = 10 % 3; // 1**Exponentiation (ES6)let power = 2 ** 3; // 8++Incrementlet x = 5; x++; // x is now 6--Decrementlet y = 10; y--; // y is now 9Comparison OperatorsComparison operators evaluate values and return true or false.OperatorDescriptionExample==Equal to (loose comparison)5 == "5" // true===Strictly equal to5 === "5" // false!=Not equal to10 != 5 // true!==Strictly not equal10 !== "10" // true>Greater than7 > 5 // true<Less than3 < 8 // true>=Greater than or equal to5 >= 5 // true<=Less than or equal to4 <= 6 // trueLogical OperatorsLogical operators allow complex logical expressions by combining multiple conditions.OperatorDescriptionExample&&Logical AND(5 > 3) && (10 > 8) // true``!Logical NOT!(5 > 3) // false&& returns true only if both conditions are true.|| returns true if at least one condition is true.! negates the result, converting true to false and vice versa.Assignment OperatorsAssignment operators assign values to variables and modify them in shorthand.OperatorDescriptionExample=Assignlet a = 10;+=Add and assigna += 5; // a = a + 5-=Subtract and assigna -= 3; // a = a - 3*=Multiply and assigna *= 2; // a = a * 2/=Divide and assigna /= 2; // a = a / 2%=Modulus and assigna %= 3; // a = a % 3**=Exponentiate and assigna **= 2; // a = a ** 2Expressions in JavaScriptExpressions are combinations of values, variables, and operators that JavaScript evaluates to produce a result.Types of Expressions:Arithmetic Expressions – let result = (5 + 2) * 3; // 21String Expressions – let fullName = "John" + " " + "Doe"; // "John Doe"Logical Expressions – let isValid = (5 > 3) && (10 > 8); // trueAssignment Expressions – let x = 10;You are reading Part 3 of the 39-part series: JavaScript Skill Progression: The Path from Beginner to Extreme. [Level 1]
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.