Skip to main content

Strings

In javascript, string can be created by wraping inside a double quotes("") or single quotes('').

Example

"Hello world!";
"Hi, hello";
Note

There is no difference while using single quotes or double quotes.

String property

The .length property can be used to determine the length of the string.

Which can be explained using an example

// Find the length of the string "hello world!"
let string = "hello world!";
console.log(string.length); // 12

Basic string methods

Some common methods for string are:

.toLowerCase()

This will return a new string with all characters in lower case.

"Hello World!".toLowerCase(); // hello world!

.toUpperCase()

This will return a new string with all characters in upper case.

"Hello World!".toUpperCase(); // HELLO WORLD!
Note

.toUpperCase() and .toLowerCase() requires () but .length() not. It is because .length is a property(a value that is already computed) whereas others are action that we are performing. So they require ().