Q1. What is a String in JavaScript?
A string is a data type used to store text or characters. Strings are written inside quotes.
JavaScript allows three types of quotes:
Example
JavaScript allows three types of quotes:
- Single quotes (' ')
- Double quotes (" ")
- Backticks (` `)
let name = "John";let city = 'London';let message = `Hello World`;Q2. What is String Concatenation?
String concatenation means joining two or more strings together.
Example
Output
Example
let firstName = "John";let lastName = "Doe";
let fullName = firstName + " " + lastName;console.log(fullName);Output
John DoeQ3. What is Template Literal in JavaScript?
Template literals allow embedding variables and expressions inside strings using backticks.
Example
Output
Template literals make string formatting easier.
Example
let name = "John";let message = `Welcome ${name}`;console.log(message);Output
Welcome JohnTemplate literals make string formatting easier.
Q4. How Can You Find the Length of a String?
JavaScript provides the length property to find the number of characters in a string.
Example
Output
Example
let text = "JavaScript";console.log(text.length);Output
10Q5. How Can You Convert String Case in JavaScript?
JavaScript provides methods to change letter case.
toUpperCase( )
toLowerCase( )
toUpperCase( )
let text = "hello";console.log(text.toUpperCase());toLowerCase( )
let text = "HELLO";console.log(text.toLowerCase());