Home JavaScript check if variable exists (is defined/initialized)
Reply: 0

JavaScript check if variable exists (is defined/initialized)

user358
1#
user358 Published in June 25, 2018, 4:01 am

Which method of checking if a variable has been initialized is better/correct? (Assuming the variable could hold anything (string, int, object, function, etc.))

if (elem) { // or !elem

or

if (typeof(elem) !== 'undefined') {

or

if (elem != null) {
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.479739 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO