JavaScript: Return true if the specified value is null, false otherwise
JavaScript fundamental (ES6 Syntax): Exercise-196 with Solution
Check If Null
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:
Flowchart:
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics