4 examples of 'javascript check empty variable' in JavaScript

Every line of 'javascript check empty variable' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
127function emptyCheck(v) {
128 return v != null && v.length > 0;
129}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

626function isVariableEmpty(variable) {
627 return variable === "" || variable === presenter.configuration.emptyAnswer;
628}
1171function isLikeEmpty(inputVar) {
1172 if (typeof inputVar !== 'undefined' && inputVar !== null) {
1173 let strTemp = JSON.stringify(inputVar);
1174 strTemp = strTemp.replace(/\s+/g, ''); // remove all whitespaces
1175 strTemp = strTemp.replace(/\"+/g, ""); // remove all >"<
1176 strTemp = strTemp.replace(/\'+/g, ""); // remove all >'<
1177 strTemp = strTemp.replace(/\[+/g, ""); // remove all >[<
1178 strTemp = strTemp.replace(/\]+/g, ""); // remove all >]<
1179 if (strTemp !== '') {
1180 return false;
1181 } else {
1182 return true;
1183 }
1184 } else {
1185 return true;
1186 }
1187}
23function isNotEmpty(variable) {
24 return (undefined !== variable && null !== variable);
25}

Related snippets