Here’s a sample OfficeScript that demonstrates how to compare various types of data using logical operators such as AND, OR, NOT, and comparison operators like equal to (=), not equal to (<>), greater than (>), less than (<), etc.
function compareData() { // Sample variables var number1 = 10; var number2 = 20; var string1 = "Hello"; var string2 = "World"; var boolean1 = true; var boolean2 = false; // Comparisons using logical operators and comparison operators var result1 = (number1 > number2) && (string1 === "Hello"); var result2 = (string1 !== string2) || (boolean1 && boolean2); var result3 = !(boolean1 && boolean2); // Logging the comparison results console.log(result1); console.log(result2); console.log(result3); }
In this example, the compareData
function performs the following comparisons:
It compares
number1
andnumber2
using the greater than (>
) operator, andstring1
with the string"Hello"
using the strict equality (===
) operator. The result is stored inresult1
.It compares
string1
andstring2
using the not equal to (!==
) operator, and comparesboolean1
andboolean2
using the logical AND (&&
) operator. The overall result is computed using the logical OR (||
) operator and stored inresult2
.It performs a logical NOT (
!
) operation on the result ofboolean1 && boolean2
, and stores the inverted result inresult3
.
Finally, the example logs the comparison results to the console.
You can call the compareData
function to see the comparison results in the console output.
Please note that OfficeScripts are only supported in Excel for the web and Excel Online, and they may have limitations compared to other programming environments.