JavaScript check if variable exists (is defined/initialized) August 26, 2022 by Tarik You want the typeof operator. Specifically: if (typeof variable !== 'undefined') { // the variable is defined }