Strings Introduction in JavaScript

 let name = "Harry"  //Here, double quotes is used

console.log(name.length);
console.log(name[0]);
console.log(name[1]);
console.log(name[2]);
console.log(name[3]);
console.log(name[4]);
let name2 = 'Harry' //Here, single quotes is used
console.log(name2.length);

// Template literals
let boy1 = "Pramod";
let boy2 = "Nikhil";
//Nikil is a friend of Pramod
let sentence = `${boy2} is a friend of ${boy1}`;
console.log(sentence);

//Escape Sequence Characters
let fruit = 'Bana\'na';
console.log(fruit);

let animal = "Elep\"hant";
console.log(animal);

let games = "super\nMario";     //Newline
console.log(games);

let animalTwo = "Buff\talo";    //Tab
console.log(animalTwo);

let fruitTwo = "Pine\rapple";   //Carriage return
console.log(fruitTwo);


OUTPUT :
5 H a r r y 5 Nikhil is a friend of Pramod Bana'na Elep"hant super Mario Buff alo apple

Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript