w3resource

JavaScript: Create the value of NOR of two given booleans

JavaScript Basic: Exercise-124 with Solution

Write a JavaScript program to create the NOR value of two given booleans.

Note: In boolean logic, logical nor or joint denial is a truth-functional operator which produces a result that is the negation of logical or. That is, a sentence of the form (p NOR q) is true precisely when neither p nor q is true - i.e. when both of p and q are false

Sample Example:

For x = true and y = false, the output should be logical_Nor(x, y) = false; For x = false and y = false, the output should be logical_Nor(x, y) = true.

Sample Solution:

JavaScript Code:

// Function to perform logical NOR operation
function test_logical_Nor(a, b) {
  return (!a && !b); // Returns true only if both a and b are false
}

// Testing logical NOR operation with different input values
console.log(test_logical_Nor(true, false));  // Output: false (logical NOR of true and false is false)
console.log(test_logical_Nor(false, false)); // Output: true (logical NOR of false and false is true)
console.log(test_logical_Nor(true, true));   // Output: false (logical NOR of true and true is false) 

Output:

false
true
false

Live Demo:

See the Pen javascript-basic-exercise-124 by w3resource (@w3resource) on CodePen.


Flowchart:

Flowchart: JavaScript - Create the value of NOR of two given booleans

ES6 Version:

// ES6 function to perform logical NOR operation
const test_logical_Nor = (a, b) => {
  return (!a && !b); // Returns true only if both a and b are false
};

// Testing logical NOR operation with different input values
console.log(test_logical_Nor(true, false));  // Output: false (logical NOR of true and false is false)
console.log(test_logical_Nor(false, false)); // Output: true (logical NOR of false and false is true)
console.log(test_logical_Nor(true, true));   // Output: false (logical NOR of true and true is false)

Improve this sample solution and post your code through Disqus.

Previous: JavaScript program to find if the members of an given array of integers is a permutation of numbers from 1 to a given integer.
Next: JavaScript program to find the longest string from a given array.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/javascript-exercises/javascript-basic-exercise-124.php