The Beginner’s Guide to JavaScript Strings

The JavaScript string is an object that represents a sequence of characters.

There are 2 ways to create strings in JavaScript

  1. By string literal
  2. By string object (using new keyword)

1) By string literal

The string literal is created using double quotes. The syntax of creating a string using string literal is given below

 Var str= “This is a string”;        
const str="This is a string";


// Output : "This is a string"        

2) By string object (using new keyword)

The syntax of creating a string object using a new keyword is given below


Var str= new String(“This is a string”);        

Here new keyword is used for creating string

var str=new String("hello how are you"); 


// Output : String { "hello how are you" }        

There are various string methods available in javascript

i) charAt() method

It provides the char value present at the specified index.

var str="javascript";  

// Output : "c"        

ii) concat() method

It provides a combination of two or more strings.

var a="javascript ";  
var b="is very popular";  
var c=a.concat(b);


// Output : "javascript is very popular"        

iii) toLowerCase()

It converts the given string into a lowercase letter

var a="JavaScript Is Popular";  
var b=a.toLowerCase();  

// Output :"javascript is popular"        

iv) toUpperCase()

It returns the given string in uppercase letters.

var a="JavaScript Is Popular";  
var b=a.toUpperCase();  


// Output :"JAVASCRIPT IS POPULAR"        
Posted in

Ankit Patel

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top