A Depth introduction in JavaScript strings
JavaScript is a scripting, interpreted programming language used both on the client-side and server-side.
Brendan Eich Invented JavaScript 1995. Brenden Eich is a Netscape engineer. JavaScript programs add to web pages in the Netscape Navigator browser.
Fact : It’s originally name is LiveScript, but it was renamed JavaScript in a marketing decision, because at This time Java language was being heavily marketed and was gaining popularity.
JavaScript Fundamentals :
Variables, data types , Code Structure, Operators, Functions, Data types, Type conversion, Comparisons, Conditionals etc..
JavaScript Data Types :
1. Primitive Data Types (stack)
- String, number , Boolean , null, undefined, symbol (ES2015)
2. Reference Data Types (non-primitive data type) (Heap)
Object
- Function, Array, date, Regular expressions
Let’s Start With JavaScript String :
What is A String?
JavaScript string stores a series of characters like : “Programming Hero”.
A string can be any text inside double or single quotes or using the backtick character Like : `IPL Postponed due to Covid-19 pandemic`
Slice method
The slice() method is used to fetch the part of the string and returns the new string.
The method takes 2 parameters: start position, end position .
Note : JavaScript counts positions from zero.
Substr method
The substr() method return at the parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
startsWith, endsWith Method
startsWith
- The startsWith() method determines whether a string begins with the characters of a specified string.
- Result Is : returns true if the string Starts with the characters, and Not Starts with the characters Then returns false.
endsWith
- The endsWith() method
Checks whether a string ends with a specified string. - Result Is : returns true if the string End’s with the specified characters, and Not End’s with this characters Then returns false.
Note: The startsWith() Or endsWith() method is case sensitive.
indexOf , lastIndexOf
indexOf
- The indexOf() method returns strings of the first positions strings of a specified value in a string.
- Return Value Is Number.
- If the value not find then returns -1
lastIndexOf
- The lastIndexOf() method returns strings of the end positions strings of a specified value in a string.
- Return Value Is Number.
- If the value not find then returns -1
Replace Method
- Replaces A string with another string, and returns a new string without modifying the original string.
Note : Required Two Arguments Must Have Provided
charAt Method
- charAt() returns the character from the specified index.
- Characters in a string are indexed from left to right.
- The index of the first character is 0, and the index of the last character in a string
toUpperCase, toLowerCase Method
toUpperCase()
- toUppercase Method Converts a string to uppercase letters.
toLowerCase()
- Converts a string to lowercase letters.
Concat Method
- Join two strings
- The concat() method is used to join two and or more strings.
It’s not change the previous strings. - But returns a new string containing the text of the joined strings.
Trim Method
- Removes whitespace from both ends of a string
Note: The trim() method does not change the original string.
trimStart, trimEnd method
- The trimStart() method removes whitespace at The starting of a string.
- The trimEnd() method removes whitespace at The end of a string.