About a very long command in java script

If I have too many words to type in a given line, how to make sure that extra words continue to function in next line?

For instance, I can have this code:

var myString =’Many’

console.log(` I am trying to type ${myString} many many many many many many many many many in a single command and my code should still run smoothly.`)
1 Like

You can turn on line wrap in the ide settings or splits the string up into 2 and hitting enter in between them.

when you said “or” , are you sure you didn’t mean " and" ?

No, you can do 1 OR the other you can do both but you just need to do one

A very long string can be represented with back ticks which supports line breaks (unescaped newlines).

longString = `Template literals are sometimes informally called
template strings, but they aren't string literals
and can't be used everywhere a string literal can
be used. Also, a tagged template literal may not
result in a string; it's up to the tag function
what it creates (if anything).`

Template literals (Template strings) - JavaScript | MDN

1 Like

so we not only need to hit enter but also use back ticks?

1 Like

Yes, back ticks are what trigger the needed support for line breaks, and also the expression templates, ${} that permit interpolation.

what did you mean when you mentioned “expression templates?” I know ${} is for interpolation.

${} is the expression part. We can write any expression and have the evaluation interpolated.

hoursWorked = 40
wagePerHour = 15
console.log(`Hours: ${hoursWorked}
Wage:  ${wagePerHuor}
Gross: ${hoursWorked * wagePerHour}`)
1 Like