Introduction
Javascript is the most powerful and widely usable language which helps you to create production-based websites. Javascript is used in client-side development as well as backend development and many more things which you can develop with the javascript. JavaScript strings are for storing and manipulating text. Javascript strings contain various methods to manipulate text with DOM (Document Object Model). On javascript strings, are the most common questions asked in interviews. Now we will see the various methods of javascript strings.
String: String is a sequence of characters for example “Hashnode is awesome”.Now there are multiple ways to create a string in javascript but the most common methods are
let text = "Hello hashnode Reader"; // double quotes
let text = ‘Thankyou for reading’; // single quotes
let text = `Hello hashnode Reader`; // backticks
You can use the single quote as well as double quotes to create string and backticks is new ways to write javascript string but always prefer to use double quotes for good practice in javascript.
Javascript String Methos:
1. Length: Javascript length property returns the lengths of the string
let str="Hashnode";
return str.length();
2. slice(): Javascript slice method extracts a part of a string and returns the extracted part in a new string.
let str = "Javascript, React, Node";
let part = str.substr(6); // Javascript
3. Split(): Converts string into an array.
let str= "Hashnode";
Return str.split(); // [‘H’,’a’,’s’,’h’,’n’,’o’,’d’,’e’ ]
4. toUpperCase():- & toLowerCase() : toUperCase conver string into uppercase letter. toLowerCase onver string into uppercase letter.
console.log("Hello Javascript Developer".toUpperCase());
// HELLO JAVASCRIPT DEVELOPER
console.log("Hello Javascript Developer".toLowerCase());
// hello javascript developer
5. fromCharCode(): method returns a string created by using the specified sequence of Unicode values.
String.fromCharCode(65,66,77) // ABC
These are the most common string methods in javascript you can play around with and practice but there are also various properties of javascript strings like substr(), replace(), concat(), trim(), and so on….
here you May have seen javascript strings and various methods for javascript strings. Hey, I'm Ganesh 🖐 I write articles on web development and share valuable resources which might help you as a developer or beginner. for more content
- follow me (@ganesh_patil )
- You can also connect with me on Twitter to get more content related to javascript development
- Thank you for the support friends!