JavaScript Strings The startsWith() Method Check if a string starts with "Hello": The startsWith() method is not supported in Internet Explorer. let text = "Hello world, welcome to the universe."; document.getElementById("demo").innerHTML = text.startsWith("Hello"); ...
JavaScript Regular Expression The /i Modifier A case-insensitive search for "w3schools" in a string: let text = "Visit W3Schools"; let pattern = /w3schools/i; let result = text.match(pattern); document.getElementById("demo").innerHTML = result; ...
JavaScript async / await Wait 3 seconds (3000 milliseconds) for this page to change. async function myDisplay() { let myPromise = new Promise(function(resolve) { setTimeout(function() {resolve("I love You !!");}, 3000); }); document.getElementById("demo").innerHTML ...
JavaScript Arrow Functions With arrow functions, you don't have to type the function keyword, the return keyword, and the curly brackets. Arrow functions are not supported in IE11 or earlier. const x = (x, y
JavaScript Numbers Integer Precision Integers (numbers without a period or exponent notation) are accurate up to 15 digits: let x = 999999999999999; let y = 9999999999999999; document.getElementById("demo").innerHTML = x + "" + y; ...
JavaScript Prompt Try it function myFunction() { let text; let person = prompt("Please enter your name:", "Harry Potter"); if (person == null || person == "") { text = "User cancelled the prompt."; } else { text = "Hello " + person + "! How are you ...
<!DOCTYPE html> JavaScript Objects To test if an object does not exist, test if the type is undefined: document.getElementById("demo").innerHTML = typeof myObj === "undefined";
JavaScript Regular Expressions The test() method returns true if it finds a match, otherwise false. Search a string for the character "e": let text = "The best things in life are free"; let pattern = /e/; let result = pattern.test(text); document.getElem...
var myObject = {"customers":[ {"CustomerName":"Alfreds Futterkiste","Color":"w3-red"}, {"CustomerName":"Ana Trujillo Emparedados y helados","Color":"w3-green"}, {"CustomerName":"Antonio Moreno Taquer a","Color":"w3-blue"}, {"CustomerName":"Around the Horn","Color"...
<!DOCTYPE html> JavaScript Numbers The toString() Method Convert a number to a string using base 2: let num = 15; let text = num.toString(2); document.getElementById("demo").innerHTML = text; ...