{"id":30,"date":"2019-03-27T13:32:02","date_gmt":"2019-03-27T13:32:02","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/javascript\/?p=30"},"modified":"2020-08-06T06:02:08","modified_gmt":"2020-08-06T06:02:08","slug":"05-javascript-operators","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/","title":{"rendered":"JavaScript &#8211; Operators"},"content":{"rendered":"<p>In the Lesson 4, we discussed <a href=\"https:\/\/www.kindsonthegenius.com\/javascript\/javascript-data-types-variables\/\">JavaScript Variables<\/a>. In this lesson, we will examine Operators. Is there a relationship between the two? Yes. Operators work with operands (which are variables sometimes). For example, x = y +z. Here the &#8216;+&#8217; sign is an operator while y and z are operands.<\/p>\n<p>&nbsp;<\/p>\n<p>So we would consider 5 JavaScript operators:<\/p>\n<ol class=\"list\">\n<li><a href=\"#t1\">Arithmetic Operators<\/a><\/li>\n<li><a href=\"#t2\">Comparison Operators<\/a><\/li>\n<li><a href=\"#t3\">Logical Operators (Relational Operators)<\/a><\/li>\n<li><a href=\"#t4\">Bitwise Operators<\/a><\/li>\n<li><a href=\"#t5\">Assignment Operators<\/a><\/li>\n<li><a href=\"#t6\">Conditional Operator<\/a><\/li>\n<li><a href=\"#t7\">The typeof Operator<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Arithmetic Operators<\/strong><\/h4>\n<p>You use arithmetic operators to perform calculations. There are 7 of them listed in the table below.<\/p>\n<p>The operations assume x = 10 and y = 20<\/p>\n<p>&nbsp;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Sr.No.<\/th>\n<th>Operator &amp; Description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>+ (Addition)<\/b><\/p>\n<p>Adds the two operands<\/p>\n<p><b>Example:<\/b> x + y will give 30<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>&#8211; (Subtraction)<\/b><\/p>\n<p>Subtracts the second operand, x from the first one, y<\/p>\n<p><b>Example:<\/b> x &#8211; y will give -10<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>* (Multiplication)<\/b><\/p>\n<p>Multiply the two operands<\/p>\n<p><b>Example:<\/b> x * y will give 200<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>\/ (Division)<\/b><\/p>\n<p>Divide the numerator x by the denominator y<\/p>\n<p><b>Example:<\/b> y \/ x will give 2<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>% (Modulus)<\/b><\/p>\n<p>Returns the remainder of an integer division<\/p>\n<p><b>Example:<\/b> x% y will give 0<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>++ (Increment)<\/b><\/p>\n<p>Takes only one operand. Increases an integer value of the operand by one.<\/p>\n<p><b>Example:<\/b> x++ will give 11<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><b>&#8212; (Decrement)<\/b><\/p>\n<p>Takes only one operand. Decreases an integer value by one<\/p>\n<p><b>Example:<\/b> x&#8211; will give 9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>While the addition operator works with numbers, it can also work with strings. Hence you can add two strings together.<\/p>\n<p>For example &#8220;name&#8221; + 20 will give name 20.<\/p>\n<p>In this way, the &#8216;+&#8217; is called a &#8216;concatenation&#8217; operator. It concatenates or combines two strings. The would be discussed more in later chapters.<\/p>\n<p>The html file below shows how arithmetic operators work.<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Arithmetic Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">33<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> z <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Test\"<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"x + y = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">+<\/span> y;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"x - y = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">-<\/span> y;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"x \/ y = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">\/<\/span> y;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"x % y = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">%<\/span> y;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"x + y + z = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">+<\/span> y <span style=\"color: #333333;\">+<\/span> x;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #333333;\">++<\/span>x;\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"++x = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> <span style=\"color: #333333;\">++<\/span>x;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #333333;\">--<\/span>y;\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"--y = \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> <span style=\"color: #333333;\">--<\/span>y;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>\r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>If you view this file, the output would be as shown below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">x + y = 43\r\nx - y = 23\r\nx \/ y = 3.3\r\nx % y = 3\r\nx + y + z = 76\r\n++x = 35\r\n--y = 8\r\nYou can try different values for x and y \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Comparison Operators<\/strong><\/h4>\n<p>You use comparison operators to compare a value against another value. The table below gives a list of comparison operators in JavaScript.<\/p>\n<p>We assume x = 10 and y = 20<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SNo.<\/th>\n<th>Operator and brief description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>= = (Equal)<\/b><\/p>\n<p>Checks if the value of two operands are equal , if they are, then the condition becomes true. Otherwise, false<\/p>\n<p><b>Example:<\/b> (x == y) is not true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>!= (Not Equal)<\/b><\/p>\n<p>Checks if the value of two operands are equal not equal, if the values are not equal, then the condition becomes true.<\/p>\n<p><b>Example:<\/b> (x != y) is true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>&gt; (Greater than)<\/b><\/p>\n<p>Checks if the value of the left operand is greater than the value of the right operand, if true, then the condition becomes true. Otherwise the condition becomes false.<\/p>\n<p><b>Example:<\/b> (x &gt; y) is not true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>&lt; (Less than)<\/b><\/p>\n<p>Checks if the value of the left operand is less than the value of the right operand, if true, then the condition becomes true.<\/p>\n<p><b>Example:<\/b> (x &lt; y) is true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>&gt;= (Greater than or Equal to)<\/b><\/p>\n<p>Checks if the value of the left operand is greater than or equal to the value of the right operand, if true, then the condition becomes true. Otherwise, false<\/p>\n<p><b>Example:<\/b> (x &gt;= y) is not true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>&lt;= (Less than or Equal to)<\/b><\/p>\n<p>Checks if the value of the left operand is less than or equal to the value of the right, if they are equal, then the condition becomes true.<\/p>\n<p><b>Example:<\/b> (x &lt;= y) is true.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The html file below shows how the comparison operator works. I recommend you take time to examine it. Also watch the video lesson for clarification.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Comparison Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n       <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">20<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n      \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x == y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">==<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &lt; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&lt;<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &gt; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&gt;<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x != y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">!=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &gt;= y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&gt;=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &lt;= y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&lt;=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span> \r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>If you view this file in the browser, then the output would be:<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">(x == y) =&gt; false\r\n(x <span style=\"color: #007700;\">&lt; y<\/span>) =<span style=\"color: #007700;\">&gt;<\/span> true\r\n(x &gt; y) =&gt; false\r\n(x != y) =&gt; true\r\n(x &gt;= y) =&gt; false\r\n(x <span style=\"color: #ff0000; background-color: #ffaaaa;\">&lt;<\/span>= y) =&gt; true\r\nYou can try different values for x and y \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Logical Operators (Relational Operators)<\/strong><\/h4>\n<p>Logical operator are used for performing logical operations. Let&#8217;s take some examples to illustrate this.<\/p>\n<p>Assuming x = 10 and y = 20, then the table below holds<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SNo.<\/th>\n<th>Operator and brief description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>&amp;&amp; (Logical AND)<\/b><\/p>\n<p>If both of the operands are non-zero, then the condition holds true. Otherwise false<\/p>\n<p><b>Example:<\/b> (x &amp;&amp; y) is true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>|| (Logical OR)<\/b><\/p>\n<p>If any of the two operands are non-zero, then the condition holds true. Otherwise false<\/p>\n<p><b>Example:<\/b> (x || y) is true.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>! (Logical NOT)<\/b><\/p>\n<p>It takes only one operand. Reverses the logical state of the operand. If a condition is true, then the Logical NOT operator will make it false.<\/p>\n<p><b>Example:<\/b> ! (x &amp;&amp; y) is false.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Now you can run the code below to see how logical operations work. I also recommend you change up the values of x and y and see what happens.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Logical Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n       <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">true<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">false<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n      \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &amp;&amp; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&amp;&amp;<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x || y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">||<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"!(x &amp;&amp; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (<span style=\"color: #333333;\">!<\/span>(x <span style=\"color: #333333;\">&amp;&amp;<\/span> y));\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>     \r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>If you view this html file, then you will have the output below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">(x <span style=\"color: #ff0000; background-color: #ffaaaa;\">&amp;&amp;<\/span> y) =&gt; false\r\n(x || y) =&gt; true\r\n!(x <span style=\"color: #ff0000; background-color: #ffaaaa;\">&amp;&amp;<\/span> y) =&gt; true\r\nYou can try different values for x and y \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Bitwise Operators<\/strong><\/h4>\n<p>Bitwise operators are used to perform certain operations on the individual bits of the binary equivalent of the operator. To understand how it works, you need to have an idea of binary numbers.<\/p>\n<p>The table below shows how bitwise operators work.<\/p>\n<p>We assume x = 2 and y = 3<\/p>\n<p>&nbsp;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SNo.<\/th>\n<th>Operator and brief description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>&amp; (Bitwise AND)<\/b><\/p>\n<p>It performs a Boolean AND operation on each bit of its integer arguments.<\/p>\n<p><b>Example:<\/b> (x &amp; y) is 2.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>| (BitWise OR)<\/b><\/p>\n<p>It performs a Boolean OR operation on each of the bit of its integer operand.<\/p>\n<p><b>Example:<\/b> (x | y) is 3.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>^ (Bitwise XOR)<\/b><\/p>\n<p>It performs a Boolean exclusive OR (XOR) operation on each bit of the given integer arguments. Exclusive OR means that either of the operand, just one is true or operand two is true, but not both.<\/p>\n<p>101 ^ 111 = 010 (it&#8217;s 1 only for the middle bit where)<\/p>\n<p><b>Example:<\/b> (x ^ y) is 1.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>~ (Bitwise Not)<\/b><\/p>\n<p>It is a unary(works on a single operand) operator and operates by reversing all its bits in the operand.<\/p>\n<p><b>Example:<\/b> (~y) is -4.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>&lt;&lt; (Bitwise left Shift)<\/b><\/p>\n<p>It moves all the bits in its first operand to the left by the number of places given in the second operand. New bit spaces are filled with zeros. Shifting a value left by one position is equivalent to multiplying by 2, shifting two positions is equivalent to multiplying by 4. And so one.<\/p>\n<p><b>Example:<\/b> (y &lt;&lt; 1) is 4.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>&gt;&gt; (Bitwise right Shift)<\/b><\/p>\n<p>Binary Right Shift Operator. The left operand\u2019s value is moved right by the number of bits specified by the right operand.<\/p>\n<p><b>Example:<\/b> (x &gt;&gt; 1) is 1.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><b>&gt;&gt;&gt; (Bitwise right shift with Zero)<\/b><\/p>\n<p>This operator is just like the &gt;&gt; operator, except that the bits shifted in on the left are always zero.<\/p>\n<p><b>Example:<\/b> (x &gt;&gt;&gt; 1) is 1.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The html file below illustrates how the bitwise operator work<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Bitwise Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>; <span style=\"color: #888888;\">\/\/ Binary equivalent of 10<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>; <span style=\"color: #888888;\">\/\/ Binary equivalent of 11<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &amp; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&amp;<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x | y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">|<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x ^ y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">^<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(~y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (<span style=\"color: #333333;\">~<\/span>y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(x &lt;&lt; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&lt;&lt;<\/span> b);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"(a &gt;&gt; y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&gt;&gt;<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>      \r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>If you view the html file above, you will have the output below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">(x <span style=\"color: #ff0000; background-color: #ffaaaa;\">&amp;<\/span> y) =&gt; 2\r\n(x | y) =&gt; 3\r\n(x ^ y) =&gt; 1\r\n(~y) =&gt; -4\r\n(x <span style=\"color: #ff0000; background-color: #ffaaaa;\">&lt;<\/span><span style=\"color: #007700;\">&lt; y<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">)<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">=<\/span><span style=\"color: #007700;\">&gt;<\/span> \r\nYou can try different values for x and y \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Assignment Operators<\/strong><\/h4>\n<p>You probably have used some assignment operators before. The assignment operators support in JavaScript are given below:<\/p>\n<p>&nbsp;<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Sr.No.<\/th>\n<th>Operator &amp; Description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>= (Simple Assignment )<\/b><\/p>\n<p>Assigns values from the right side operand to the left side operand<\/p>\n<p><b>Example:<\/b> z = x + y will assign the value of x + y into z<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>+= (Add and Assignment)<\/b><\/p>\n<p>It adds the right operand to the left operand and then assigns the result to the left operand.<\/p>\n<p><b>Example:<\/b> z += x is equivalent to z = z + x<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>\u2212= (Subtract and Assignment)<\/b><\/p>\n<p>It subtracts the right operand from the left operand and then assigns the result to the left operand.<\/p>\n<p><b>Example:<\/b> z -= x is equivalent to z = z &#8211; x<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>*= (Multiply and Assignment)<\/b><\/p>\n<p>It multiplies the right operand with the left operand and then assigns the result to the left operand.<\/p>\n<p><b>Example:<\/b> z *= x is equivalent to z = z * x<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>\/= (Divide and Assignment)<\/b><\/p>\n<p>It divides the left operand with the right operand and then assigns the result to the left operand.<\/p>\n<p><b>Example:<\/b> z \/= x is equivalent to z = z \/ x<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>%= (Modules and Assignment)<\/b><\/p>\n<p>It takes modulus using two operands and assigns the result to the left operand.<\/p>\n<p><b>Example:<\/b> z %= x is equivalent to z = z % x<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The html file below illustrates these assignment operators discussed. I recommend you view it and also change the values to see what you get.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Assignment Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">33<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Value of x =&gt; (x = y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Value of x =&gt; (x += y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">+=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Value of x =&gt; (x -= y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">-=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Value of x =&gt; (x *= y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">*=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Value of x =&gt; (x \/= y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">\/=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Value of x =&gt; (x %= y) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">%=<\/span> y);\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>      \r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>If you view the file above, then you will have the output.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Value of x =&gt; (x = y) =&gt; 10\r\nValue of x =&gt; (x += y) =&gt; 20\r\nValue of x =&gt; (x -= y) =&gt; 10\r\nValue of x =&gt; (x *= y) =&gt; 100\r\nValue of x =&gt; (x \/= y) =&gt; 10\r\nValue of x =&gt; (x %= y) =&gt; 0\r\nYou can try different values for x and y \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. Conditional Operator (?:)<\/strong><\/h4>\n<p>The is operation applies to an expression. It first evaluates the expression for either true or false. Then it executes one of the two specified statements depending on the result of the initial evaluation.<\/p>\n<p>The syntax of the contitional operator is:<\/p>\n<p><strong><em>(condition) ? x : y<\/em><\/strong><\/p>\n<p>If condition is true. the value x: otherwise value y<\/p>\n<p>Let&#8217;s take an example.<\/p>\n<p>The code below illustrates the use of conditional operator.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Conditional Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">20<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write (<span style=\"background-color: #fff0f0;\">\"((ax &gt; y) ? 100 : 200) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&gt;<\/span> y) <span style=\"color: #333333;\">?<\/span> <span style=\"color: #0000dd; font-weight: bold;\">100<\/span> <span style=\"color: #333333;\">:<\/span> <span style=\"color: #0000dd; font-weight: bold;\">200<\/span>;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            <span style=\"color: #007020;\">document<\/span>.write (<span style=\"background-color: #fff0f0;\">\"((x &lt; y) ? 100 : 200) =&gt; \"<\/span>);\r\n            result <span style=\"color: #333333;\">=<\/span> (x <span style=\"color: #333333;\">&lt;<\/span> y) <span style=\"color: #333333;\">?<\/span> <span style=\"color: #0000dd; font-weight: bold;\">100<\/span> <span style=\"color: #333333;\">:<\/span> <span style=\"color: #0000dd; font-weight: bold;\">200<\/span>;\r\n            <span style=\"color: #007020;\">document<\/span>.write(result);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>        \r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>If you view the file, you will have the output below:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">((ax &gt; y) ? 100 : 200) =&gt; 200\r\n((x <span style=\"color: #007700;\">&lt; y<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">)<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">?<\/span> <span style=\"color: #0000cc;\">100<\/span> <span style=\"color: #0000cc;\">:<\/span> <span style=\"color: #0000cc;\">200<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">)<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">=<\/span><span style=\"color: #007700;\">&gt;<\/span> 100\r\nYou can try different values for x and y \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. The typeof Operator<\/strong><\/h4>\n<p>This operator works on a single operand (it is a unary operator).<\/p>\n<p>The typeof operator returns the data type of the specified operand. So it could return number, string or boolean depending on the type of its operand.<\/p>\n<p>The table below summarizes the values that can be returned by the typeof operator<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th width=\"20%\">Type<\/th>\n<th>Value Returned by typeof<\/th>\n<\/tr>\n<tr>\n<td>Number data<\/td>\n<td>&#8220;number&#8221;<\/td>\n<\/tr>\n<tr>\n<td>String data<\/td>\n<td>&#8220;string&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Boolean data<\/td>\n<td>&#8220;boolean&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Object operand<\/td>\n<td>&#8220;object&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Function operand<\/td>\n<td>&#8220;function&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Undefined<\/td>\n<td>&#8220;undefined&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>&#8220;object&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The code below illustrates how the typeof operator works. I recommend you make sure to try it yourself.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;head&gt;&lt;title&gt;<\/span>Typeof  Operators Example<span style=\"color: #007700;\">&lt;\/title&gt;&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>\r\n   \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> y <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"String\"<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> linebreak <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>;\r\n         \r\n            output <span style=\"color: #333333;\">=<\/span> (<span style=\"color: #008800; font-weight: bold;\">typeof<\/span> y <span style=\"color: #333333;\">==<\/span> <span style=\"background-color: #fff0f0;\">\"string\"<\/span> <span style=\"color: #333333;\">?<\/span> <span style=\"background-color: #fff0f0;\">\"Y is String\"<\/span> <span style=\"color: #333333;\">:<\/span> <span style=\"background-color: #fff0f0;\">\"Y is Numeric\"<\/span>);\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Output =&gt; \"<\/span>);\r\n            <span style=\"color: #007020;\">document<\/span>.write(output);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         \r\n            output <span style=\"color: #333333;\">=<\/span> (<span style=\"color: #008800; font-weight: bold;\">typeof<\/span> x <span style=\"color: #333333;\">==<\/span> <span style=\"background-color: #fff0f0;\">\"string\"<\/span> <span style=\"color: #333333;\">?<\/span> <span style=\"background-color: #fff0f0;\">\"X is String\"<\/span> <span style=\"color: #333333;\">:<\/span> <span style=\"background-color: #fff0f0;\">\"X is Numeric\"<\/span>);\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Output =&gt; \"<\/span>);\r\n            <span style=\"color: #007020;\">document<\/span>.write(output);\r\n            <span style=\"color: #007020;\">document<\/span>.write(linebreak);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>         \r\n      \r\n      You can try different values for x and y\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>If you view the file, you will have the output below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Output =&gt; Y is String\r\nOutput =&gt; X is Numeric\r\nYou can try different values for x and y \r\n<\/pre>\n<p>Note: Ensure you try out all the examples yourself.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the Lesson 4, we discussed JavaScript Variables. In this lesson, we will examine Operators. Is there a relationship between the two? Yes. Operators work &hellip; <\/p>\n","protected":false},"author":395,"featured_media":31,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[3],"class_list":["post-30","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-tutorials","tag-operators-in-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript - Operators - JavaScript Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript - Operators - JavaScript Tutorial\" \/>\n<meta property=\"og:description\" content=\"In the Lesson 4, we discussed JavaScript Variables. In this lesson, we will examine Operators. Is there a relationship between the two? Yes. Operators work &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"JavaScript Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-27T13:32:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-06T06:02:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2019\/03\/Operators-in-JavaScript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"912\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"JavaScript &#8211; Operators\",\"datePublished\":\"2019-03-27T13:32:02+00:00\",\"dateModified\":\"2020-08-06T06:02:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/\"},\"wordCount\":1496,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2019\\\/03\\\/Operators-in-JavaScript.jpg\",\"keywords\":[\"Operators in JavaScript\"],\"articleSection\":[\"JavaScript Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/\",\"name\":\"JavaScript - Operators - JavaScript Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2019\\\/03\\\/Operators-in-JavaScript.jpg\",\"datePublished\":\"2019-03-27T13:32:02+00:00\",\"dateModified\":\"2020-08-06T06:02:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2019\\\/03\\\/Operators-in-JavaScript.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2019\\\/03\\\/Operators-in-JavaScript.jpg\",\"width\":912,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/05-javascript-operators\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript &#8211; Operators\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/\",\"name\":\"JavaScript Tutorial\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript - Operators - JavaScript Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript - Operators - JavaScript Tutorial","og_description":"In the Lesson 4, we discussed JavaScript Variables. In this lesson, we will examine Operators. Is there a relationship between the two? Yes. Operators work &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/","og_site_name":"JavaScript Tutorial","article_published_time":"2019-03-27T13:32:02+00:00","article_modified_time":"2020-08-06T06:02:08+00:00","og_image":[{"width":912,"height":500,"url":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2019\/03\/Operators-in-JavaScript.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"JavaScript &#8211; Operators","datePublished":"2019-03-27T13:32:02+00:00","dateModified":"2020-08-06T06:02:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/"},"wordCount":1496,"commentCount":1,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2019\/03\/Operators-in-JavaScript.jpg","keywords":["Operators in JavaScript"],"articleSection":["JavaScript Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/","url":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/","name":"JavaScript - Operators - JavaScript Tutorial","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2019\/03\/Operators-in-JavaScript.jpg","datePublished":"2019-03-27T13:32:02+00:00","dateModified":"2020-08-06T06:02:08+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2019\/03\/Operators-in-JavaScript.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2019\/03\/Operators-in-JavaScript.jpg","width":912,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/05-javascript-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/javascript\/"},{"@type":"ListItem","position":2,"name":"JavaScript &#8211; Operators"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#website","url":"https:\/\/www.kindsonthegenius.com\/javascript\/","name":"JavaScript Tutorial","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/javascript\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":2,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts\/30\/revisions\/110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/media\/31"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}