Member-only story
Object-Oriented JavaScript — Strings
JavaScript is partly an object-oriented language.
To learn JavaScript, we got to learn the object-oriented parts of JavaScript.
In this article, we’ll look at strings, which is one of the building blocks of objects.
Strings
A string is a sequence of characters to represent text.
Any values placed between single quotes, double quotes, or backticks are string.
If we have:
let s = "foo";
typeof s;
Then typeof s
returns 'string'
.
If we put nothing between the quotes, it’s still a string.
The +
operator is used to concatenate 2 strings.
If we have:
let s1 = "web";
let s2 = "site";
let s = s1 + s2;
Then we s
is 'website'
.
And typeof s
would be 'string'
.
This is a source of errors in the system.
To avoid errors, we should make sure that operators are strings.
This way, we won’t be adding anything by accident.
String Conversions
A string is converted to a number behind the scene if a number string is encountered.