You can use either double or single quotes to declare a string.
"Hello world!" // declaring with double quotes 'Hello world!' // with single quotes 'She said, "she said"' // Using double quotes within single quotes "She said, \"Hello darling\"" // Escaping quotes with a backslash
As you can see in the above example, you can use the backslash key
\" to escape the quote.
document.write("\tHello\nWorld!"); // Hello // World!
var greeting = "Hello" + "world!";
When adding numbers and strings together, you will get a string back, with the two values concatenated.
var cost = '8' + 9; // cost = '89';
The String object comes with a number of member attributes.
var sample = "Hello there." sample.length; // 12 characters sample.substring(0,5); // "Hello" sample.toUpperCase(); // "HELLO THERE."
To get input from your user, use the
prompt() method. This will display a dialog box to the user, displaying the string passed in as an parameter to
Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.$ Check price
This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.$ Check price