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 who
report accurately, you’ll keep only those who know
what you want to hear. I can think of nothing more
poisonous than to rot in the stink of your own
reflections.`

Read more on MDN

String() constructor

Test yourself

Description

Define a new function with the name

wisdom
that takes zero input parameters and returns the string value
One learns from books and example only that certain things can be done. Actual learning requires that you do those things.

Tests

  1. 1 You should define a function named wisdom.
  2. 2wisdom() should return "One learns from books and example only that certain things can be done. Actual learning requires that you do those things.".
Editor