-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JavaScript provides many string methods that let you transform, extract, search, or replace text. These methods do not modify the original string (because strings are immutable in JS) but return a new string instead.
Method | Description | Example |
---|---|---|
slice(start, end) |
Extracts part of a string | "Hello".slice(1, 4) → "ell" |
substring(start, end) |
Similar to slice() , but can't take negative indexes |
"Hello".substring(1, 4) → "ell" |
substr(start, length) |
Returns length chars from start index (deprecated) |
"Hello".substr(1, 3) → "ell" |
replace(find, replace) |
Replaces first match with new string | "Hi John".replace("John", "Sam") → "Hi Sam" |
replaceAll(find, replace) |
Replaces all matches | "a-a-a".replaceAll("a", "b") → "b-b-b" |
toUpperCase() |
Converts all letters to uppercase | "hello".toUpperCase() → "HELLO" |
toLowerCase() |
Converts all letters to lowercase | "HELLO".toLowerCase() → "hello" |
trim() |
Removes whitespace from both ends | " hello ".trim() → "hello" |
padStart(len, char) |
Pads the beginning of the string | "5".padStart(3, "0") → "005" |
padEnd(len, char) |
Pads the end of the string | "5".padEnd(3, "*") → "5**" |
repeat(n) |
Repeats the string n times |
"hi".repeat(3) → "hihihi" |
split(delimiter) |
Splits string into array based on delimiter | "a,b,c".split(",") → ["a", "b", "c"] |
"JavaScript".slice(4); // "Script"
"JavaScript".substring(0, 4); // "Java"
" hello ".trim(); // "hello"
"5".padStart(3, "0"); // "005"
"abcabc".replaceAll("a", "*"); // "*bc*bc"
Q1. How do you extract "Script"
from the string "JavaScript"
using slice()
?
Q2. How do you replace "Hello"
with "Hi"
in the string "Hello World"
?
Q3. How do you convert "good morning"
to uppercase?
Q4. How do you trim the spaces from both sides of " welcome "
?
Q5. Which method will split "apple,banana,grape"
into an array of fruits?
Q6. How do you pad the string "9"
to become "009"
using a string method?
Q7. What method can you use to repeat "ha"
4 times to form "hahahaha"
?
Q8. How do you replace all occurrences of "a"
with "*"
, in "a-a-a"
?
Q9. How do you extract the substring "ava"
from "JavaScript"
using substring()
?
Q10. What method will convert "JAVASCRIPT"
to lowercase letters?
Q1: What does "Welcome".slice(3) return?
Q2: What does "Hi John".replace("John", "Mike") return?
Q3: Which method removes whitespace from both sides of a string?
Q4: Which method converts "hello" to "HELLO"?
Q5: What does "10".padStart(4, "0") return?
Q6: What is the output of "js".repeat(3)?
Q7: Which of the following is used to split "a,b,c" into an array?
Q8: Which method replaces all matches in a string?
Q9: What does "abcabc".replaceAll("a", "*") return?
Q10: Which method extracts a string portion based on character position?