JavaScript
JavaScript String Type
Creation
Strings are generally so commonly used that most languages provide syntactic sugar for their creation; JavaScript is no exception. We can define strings by simple putting single or double quotation marks around some text.
const title = "Children of Dune"
This is equivalent to the code below.
const title = new String("Children of Dune")
Multiline strings can be defined either by explicitly using the
newline character \n or by wrapping the text in backtick
characters. In the formatting
section
we'll see that the backtick notation has many other formatting
strengths as well.
const multiLineQuote = `If you put away those whoreport accurately, you’ll keep only those who knowwhat you want to hear. I can think of nothing morepoisonous than to rot in the stink of your ownreflections.`
Read more on MDN
String() constructor
Test yourself
Description
Define a new function with the name
that takes zero input parameters and returns the string valuewisdom
One learns from books and example only that certain things can be done. Actual learning requires that you do those things.
Tests
- 1
You should define a function named
wisdom. - 2
wisdom()should return"One learns from books and example only that certain things can be done. Actual learning requires that you do those things.".