Can a space be at the beginning or end of a string?

Does it matter if a space before the quote(s) is placed before or after a string when you want to get a space between the strings?

Spaces inside the quotes will render with the string.

variable = "more text"
"Some text, " + variable

will render as Some text, more text


Console. Log (‘code ‘) + (‘me-up’)//should return code me-up//
Console.log (‘code’) + (‘ me-up’)//will return the same string results also code me-up//

1 Like

Everything should be inside the parentheses.

console.log('code ' + 'me up');

Note there are no uppercase letters in console.

Thanks. Also I have now ingrained in my left hemisphere that syntax matters in JavaScript! So double helix thanks!!$


You’re welcome!

As with most languages, yes, syntax is the foundation of code that can be interpreted. We’re nowadays less focused on good grammar and spelling in our day to day communication, but in programming there is no such laxness permitted if we wish to get the result we planned for.


It doesn’t look like it. I had the same thought, so tested both scenarios, both rendered the expected Hello World. The replies below are all about keeping things bounded by the brackets, rather than directly answering your question. If there’s someone out there with more experience/ knowledge as to why it matters where you add the space, please let us know? Thanks

console.log(‘Hello{space}’ +‘World’) will produce -----> Hello{space}World
console.log(‘Hello’ + ‘{space}World’) will produce-------> Hello{space}World

So we can use both either end of the first string or start of the second string.
please correct me if I’m wrong.

1 Like