The difference between a string and a string literal

The difference between a string and a string literal
0.0 0

#1

Please, can anyone help explain the difference between a string and a string literal?


#2

“Literal” simply means that it’s the value itself, rather than a variable.

For example:

const dog = 'Santa’s Little Helper';

Santa’s Little Helper is a string literal, whereas dog isn’t.


#3

Ok. I am getting it. Thank you.


#4

Refer to this aswell.


#5

I have gone through the article. It was helpful. Thanks.


#6

Lionel is right, that is what is meant by a “string literal”.

And Emgo-Dev is right, that there is also something called a “template literal” that relates to strings and is part of ES6, and might mistakenly be referred to as a “string literal”. They are string literals with the added feature of allowing some light templating.