empty() javascript code example

Example 1: javascript empty function

const func = () => {};
// Or
const func = Function();

Example 2: .empty() in jquery

// Remove all child nodes of the set of matched elements from the DOM
// This method does not accept any arguments.
$("div.parent").empty();

$("button").click(function(){
   $("div").empty();
});

Example 3: empty javascript

function sum(a, a, c) { // !!! syntax error
  'use strict';
  return a + a + c; // wrong if this code ran
}

Example 4: javascript check if empty

//check if string is undefined 
if (typeof myVar === 'undefined'){
  console.log("I am not defined");
}

//check if string is empty, null, or 0
var emptyString="";
if (emptyString) {
    console.log("im not empty");
}