check if string has value javascript code example

Example 1: check for substring javascript

const string = "javascript";
const substring = "script";

console.log(string.includes(substring));  //true

Example 2: javascript if string empty

// Test whether strValue is empty or is None
if (strValue) {
    //do something
}
// Test wheter strValue is empty, but not None 
if (strValue === "") {
    //do something
}

Example 3: empty string in javascript

var s; // undefined
var s = ""; // ""
s.length // 0

Example 4: check if value is a string javascript

let eventValue = event.target.value;

    if (/^\d+$/.test(eventValue)) {
      eventValue = parseInt(eventValue, 10);
    }

//If value is a string, it converts to integer. 

//Otherwise it remains integer.

Tags:

Java Example