if variable is set assign else javascript code example Example: javascript check if variable exists if (typeof myVar !== 'undefined') { // myVar is defined }