Table of Contents
Back Button
Back to Chapter
Control Statements
No items found.
Function & Events
No items found.
Array and its Types
No items found.
OOP : Object Oriented Programming
No items found.
Javascript Standards
No items found.
HTML DOM
No items found.
Javascript : Advanced 1
No items found.
Javascript : Advanced 2
No items found.
Additional JavaScript
No items found.

String

Introduction

String is a Data Type that is used to store storing and manipulating text.

Strings are written inside Double Quotes or Single Quotes.

Example :

"hello" , "Hey There" , "Any Text" , "123", "World123"

Any Thing you write inside Double Quotes is considered to be a Text by Javascript.

Declaring String

Syntax

var variableName = "Any Text";

You can use Double Quotes or Single Quotes, Both Will Work.

Example

var helloText = "Hey There! Welcome To My World"; var newHelloText = 'How Are You???'; console.log(helloText); console.log(newHelloText); // Output // Hey There! Welcome To My World // How Are You???

Escape Character

As you all know, Strings are written inside the Double quotes or Single Quotes. So, when you will try to enter a word inside double quotes then javascript will misunderstand it and thus will not give desired output

For Example :

var string1 = "Hey There!!! "We are Top Of The World"; console.log(string1); //Output ** This Program Will Not Be Executed **

Correct Program

var string1 = "Hey There!!! \"We are Top Of The World\""; console.log(string1); // Output // Hey There!!! "We are Top Of The World"

To Achieve Desired Output You have to use Backslash (\\)

Here We have list of Escape Characters. These are also used for Giving Special Functionality Like New Line or Vertical Space.

Escape Characters

String Methods

We have some Predefined Function To Perform Specific Task on String Like Converting it to Upper Case Text or Cropping some Part of The String.

Let's See them in details

We have considered str is a variable containing String.

Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?