What is String ?
- In JavaScript, a string is a primitive data type used to represent and manipulate text. It is a sequence of characters, which can include letters, numbers, symbols, and spaces.
- Strings are created by enclosing characters within single quotes ('...'), double quotes ("..."), or backticks (
...
).
Example :
let greeting = "Hello, world!";
let name = 'Alice';
let message = `Welcome, ${name}!`; // Template literal with backticks
Example :
let text = " JavaScript ";
console.log(text.length); // 14
console.log(text.trim()); // "JavaScript"
console.log(text.toUpperCase()); // " JAVASCRIPT "
Top comments (0)