strings in js code example
Example 1: js string
`hello world`
`hello!
world!`
`hello ${who}`
escape `<a>${who}</a>`
Example 2: js string
String(thing)
Example 3: js string
let longString = "This is a very long string which needs " +
"to wrap across multiple lines because " +
"otherwise my code is unreadable.";
Example 4: 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`
Example 5: js string
return 'cat'.charAt(1);
Example 6: js string
let longString = "This is a very long string which needs \
to wrap across multiple lines because \
otherwise my code is unreadable.";