{"id":663,"date":"2024-01-03T18:50:00","date_gmt":"2024-01-03T18:50:00","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=663"},"modified":"2024-02-05T10:17:51","modified_gmt":"2024-02-05T10:17:51","slug":"javascript-operators","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/javascript-operators\/","title":{"rendered":"JavaScript Operators"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">JavaScript supports a variety of operators, which are symbols used to perform operations on variables and values. Here&#8217;s an overview of some common types of operators in JavaScript:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Arithmetic Operators:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let x = 10;\nlet y = 5;\n\nconsole.log(x + y); \/\/ Addition: 15\nconsole.log(x - y); \/\/ Subtraction: 5\nconsole.log(x * y); \/\/ Multiplication: 50\nconsole.log(x \/ y); \/\/ Division: 2\nconsole.log(x % y); \/\/ Modulus: 0 (remainder after division)\nconsole.log(x ** y); \/\/ Exponentiation: 100000<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Assignment Operators:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let a = 10;\n\na += 5; \/\/ Equivalent to a = a + 5\nconsole.log(a); \/\/ Output: 15\n\na -= 3; \/\/ Equivalent to a = a - 3\nconsole.log(a); \/\/ Output: 12\n\na *= 2; \/\/ Equivalent to a = a * 2\nconsole.log(a); \/\/ Output: 24\n\na \/= 4; \/\/ Equivalent to a = a \/ 4\nconsole.log(a); \/\/ Output: 6<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Comparison Operators:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let p = 5;\nlet q = \"5\";\n\nconsole.log(p == q); \/\/ Equality (loose equality): true\nconsole.log(p === q); \/\/ Strict equality (checks value and type): false\nconsole.log(p != q); \/\/ Inequality (loose inequality): false\nconsole.log(p !== q); \/\/ Strict inequality: true\n\nconsole.log(x &gt; y); \/\/ Greater than: true\nconsole.log(x &lt; y); \/\/ Less than: false\nconsole.log(x &gt;= y); \/\/ Greater than or equal to: true\nconsole.log(x &lt;= y); \/\/ Less than or equal to: false<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Logical Operators:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let isTrue = true;\nlet isFalse = false;\n\nconsole.log(isTrue &amp;&amp; isFalse); \/\/ Logical AND: false\nconsole.log(isTrue || isFalse); \/\/ Logical OR: true\nconsole.log(!isTrue); \/\/ Logical NOT: false<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. Unary Operators:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let num = 5;\n\nconsole.log(-num); \/\/ Unary negation: -5\nconsole.log(+num); \/\/ Unary plus: 5 (no effect)\nconsole.log(++num); \/\/ Increment: 6\nconsole.log(--num); \/\/ Decrement: 5<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. Conditional (Ternary) Operator:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let age = 20;\nlet eligibility = (age &gt;= 18) ? \"Eligible\" : \"Not eligible\";\nconsole.log(eligibility); \/\/ Output: \"Eligible\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are some of the fundamental operators in JavaScript. They allow you to perform a wide range of operations, from basic arithmetic to complex conditional logic. Understanding and using these operators is essential for writing effective and concise JavaScript code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript supports a variety of operators, which are symbols used to perform operations on variables and values. Here&#8217;s an overview of some common types of operators in&#8230; <\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-663","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":1,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"predecessor-version":[{"id":664,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/663\/revisions\/664"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}