-
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
A string in JavaScript is a sequence of characters enclosed in single ('
), double ("
), or backtick (``) quotes.
let name1 = "John";
let name2 = 'Doe';
let fullName = `${name1} ${name2}`;
let str1 = "Hello";
let str2 = 'World';
let str3 = `Hello World`; // Template literal
Method / Property | Description | Example |
---|---|---|
length |
Returns the length of the string | "Hello".length → 5 |
charAt(index) |
Returns character at given index | "Hello".charAt(1) → 'e' |
toUpperCase() |
Converts to uppercase | "hello".toUpperCase() → 'HELLO' |
toLowerCase() |
Converts to lowercase | "HELLO".toLowerCase() → 'hello' |
indexOf(substr) |
Finds index of substring | "hello".indexOf("l") → 2 |
lastIndexOf(substr) |
Last occurrence of substring | "hello".lastIndexOf("l") → 3 |
includes(substr) |
Checks if substring exists | "hello".includes("e") → true |
startsWith(substr) |
Checks if string starts with value | "hello".startsWith("he") → true |
endsWith(substr) |
Checks if string ends with value | "hello".endsWith("lo") → true |
slice(start, end) |
Extracts part of string | "hello".slice(1, 4) → 'ell' |
substring(start, end) |
Similar to slice() |
"hello".substring(1, 4) |
replace(a, b) |
Replaces first match | "Hi there".replace("Hi", "Hello") → 'Hello there' |
split(delimiter) |
Splits string into array | "a,b,c".split(",") → ['a','b','c'] |
trim() |
Removes whitespace | " hello ".trim() → 'hello' |
let name = "John";
let message = `Hello, ${name}!`; // Output: Hello, John!
Q1. How do you find the length of the string "JavaScript"
?
Q2. How do you convert the string "hello"
to all uppercase letters using a built-in method?
Q3. How do you extract the substring "ava"
from the string "JavaScript"
?
Q4. How do you check whether a string "apple"
includes the letter "p"
?
Q5. How do you replace "good"
with "awesome"
in the string "good job"
?
Q6. How do you convert "HELLO"
to lowercase using a string method?
Q7. What method returns the position of the first occurrence of "a"
in "banana"
?
Q8. How do you split "red,green,blue"
into an array of words?
Q9. How do you remove leading and trailing spaces from the string " hello "
?
Q10. How do you create a greeting like "Hello, John!"
using template literals with variable name = "John"
?
Q1: Which method returns the number of characters in a string?
Q2: What does "Apple".toLowerCase() return?
Q3: Which of the following finds the first occurrence of "a" in "banana"?
Q4: Which method can convert "HELLO" to "hello"?
Q5: Which method checks if a string includes a specific word?
Q6: What is the result of "good job".replace("good", "awesome")?
Q7: Which method removes white spaces from both sides of a string?
Q8: What will "JavaScript".slice(4, 10) return?
Q9: Which of the following is used to insert variables inside strings using backticks?
Q10: Which of the following will split the string "one,two,three" into an array?