In this tutorial, we will learn about String in JavaScript. In Strings are normally defined as a sequence of character. For example “Owlbuddy” Yes you can say “Owlbuddy” is a String in the programming language. There are two ways to define String in JavaScript:
Page Contents
- Using String literal
- Using String object
Now we will check each way to create and we will try to understand it with the help of examples.
Using String literal:
In this method, we directly write var keyword and then literal for string and then we write a string in double quotes(” “). Follow this example to get a clear idea about this method.
<script>
var str="Welcome To Owlbuddy";
document.write(str);
</script>
Using String object:
In this method, we create String object using new keyword and then we pass a string in Object. Check the following example.
<script>
var str=new String("Welcome to Owlbuddy.");
document.write(str);
</script>
Basic string Methods:
Here we will check some basic string Methods. That will help you so much while working with Strings
| Method | Description |
|---|---|
| charAt() | It is use to check char at particular index. |
| concat() | It is use to concat two strings. |
| indexOf() | It is use to find index of character in String. |
| lastIndexOf() | It is use to find lat index of character n string. |
| search() | It is use to search regular expression from string. |
| replace() | It is use to replace part of string with some other char squence |
| substr() | It is use to get sub string from big string. |
| toLowerCase() | It converts whole string into lower case letters. |
| toUpperCase() | It converts whole string into upper case letters. |
| toString() | It return string form an object. |
| valueOf() | Provide primitive value of String object. |
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
