undefined, null
JavaScript
xxxxxxxxxx
function checkVariable(variable) {
if(variable == null) {
console.log('The variable is undefined or null');
}
else {
console.log('The variable is neither undefined nor null');
}
}
let newVariable;
checkVariable(5);
checkVariable('hello');
checkVariable(null);
checkVariable(newVariable);
The variable is neither undefined nor null The variable is neither undefined nor null The variable is undefined or null The variable is undefined or null
typeof
JavaScript
xxxxxxxxxx
function checkVariable(variable) {
if( typeof variable === 'undefined' || variable === null ) {
console.log('The variable is undefined or null');
}
else {
console.log('The variable is neither undefined nor null');
}
}
let newVariable;
checkVariable(5);
checkVariable('hello');
checkVariable(null);
checkVariable(newVariable);
The variable is neither undefined nor null The variable is neither undefined nor null The variable is undefined or null The variable is undefined or null
Linux - How to Install anc-api-tools
C - Find Largest Number Using Dynamic Memory Allocation
Python - How do I sort a dictionary by value?
Java - Reverse a Number
C - Count Number of Digits in an Integer
Java - Concatenate Two Arrays
Kotlin - Calculate the Sum of Natural Numbers
Linux - How to Install zlib1g-dev
Kotlin - Find Factorial of a Number
Kotlin - Convert Milliseconds to Minutes and Seconds
Kotlin - Calculate the Power of a Number
C++ - Check Whether a Number is Prime or Not
Python - I/O chat very easy chat
Java - Create Pyramid and Pattern
Kotlin - Count Number of Digits in an Integer
Kotlin - Check Whether a Number is Even or Odd
Kotlin - Get Current Date/TIme
Kotlin - Multiply two Floating Point Numbers
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month