w3resource

JavaScript: Return true if the specified value is null, false otherwise

JavaScript fundamental (ES6 Syntax): Exercise-196 with Solution

Write a JavaScript program that will return true if the specified value is null, false otherwise.

  • Use the strict equality operator to check if the value of val is equal to null.

Sample Solution:

JavaScript Code:

// Define a function 'isNull' that checks if the given value 'val' is null
const isNull = val =>
  // Check if 'val' is strictly equal to null
  val === null;

// Test cases to check if the values are null
console.log(isNull(null)); // true (the value is null)
console.log(isNull(123));  // false (the value is not null)

Output:

true
false

Visual Presentation:

JavaScript Fundamental: Return true if the specified value is null, false otherwise.
JavaScript Fundamental: Return true if the specified value is null, false otherwise.

Flowchart:

flowchart: Return true if the specified value is null, false otherwise

Live Demo:

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


Improve this sample solution and post your code through Disqus

Previous: Write a JavaScript program to check if a given argument is a number.
Next: Write a JavaScript program to check if a string is lower case or not.

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://www.w3resource.com/javascript-exercises/fundamental/javascript-fundamental-exercise-196.php