Sitemap
Faridahnajjuma

Faridahnajjuma

JAVASCRIPT STRINGS

2 min readJun 27, 2025

JavaScript string is zero or more characters written inside quotes i.e. ;

let text = “ faridah ”;

Press enter or click to view image in full size

TEMPLATE STRING AS A TYPE OF STRING

This is enclosed in backticks i.e. let text = ‘she’s often called “fidha”’;

ESCAPE CHARACTER

This must be written within quotes ,reason being JavaScript will misunderstand this string whereby to solve such a problem, one can use an backlash escape character because, it turns special characters into string characters.

Example

\” inserts a double quote in a string i.e. let text = “we are so- called/” queens/” from the east.”;

\’ inserts a single quote in a string i.e. let text = ‘It\;s alright.’;

Get Faridahnajjuma’s stories in your inbox

Join Medium for free to get updates from this writer.

\\inserts a backlash in a string i.e.

let text = “The character\\ is called backlash.”;

A safe way to break a string is by using string addition

i.e. document.getElementById(“demo”). inner HTML=”Hello ”+”Najjuma!”;

Also strings consist of template which allow multiline strings ie

let text = ‘The crazy dog jumped over a lazy cat’;

Note: strings can also be defined as objects with the keyword new:

forexample; let y = new string (“Faridah”);

let x = “Faridah”;

let y = new string (“faridah”); besides that, when using the ==operator x and y are equal i.e. let y = new string (“Faridah”); and let x = “Faridah”;

but, when using the === operator , x and y are not equal

for example;

In the first console.log statement, the == operator converts the Boolean value true to the number 1, resulting in true. In the second console.log statement, the === operator compares the two values without converting them, resulting in false.

const bool = true; const num = 1; console.log(bool == num); // true — The Boolean value true gets converted to 1 console.log(bool === num); // false — The values are different types and not equal

--

--