string() javascript code example
Example 1: is string javascript
function isString(value) {
return typeof value === 'string' || value instanceof String;
}
isString('');
isString(1);
isString({});
isString([]);
isString(new String('teste'))
Example 2: jquery cast to string
value.toString()
String(value)
value + ""
Example 3: js string
`hello world`
`hello!
world!`
`hello ${who}`
escape `<a>${who}</a>`
Example 4: js string
String(thing)
Example 5: js string
let longString = "This is a very long string which needs " +
"to wrap across multiple lines because " +
"otherwise my code is unreadable.";
Example 6: js strings
let color = "purple";
let city = 'Tokyo';
city.length;
city[0];
city[3];
'hello'.toUpperCase();
'LOL'.toLowerCase();
' omg '.trim();
'spider'.indexOf('i');
'vesuvius'.indexOf('u');
'cactus'.indexOf('z');
"pancake".slice(3);
"pancake".slice(0, 3);
"pump".replace("p", "b");
const color = "olive green";
const msg = `My favorite color is: ${color}`
const str = `There are ${60 * 60 * 24} seconds in a day`