DEV Community

Bhuvana Sri R
Bhuvana Sri R

Posted on

String In JavaScript

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
Enter fullscreen mode Exit fullscreen mode

Example :

    let text = "  JavaScript  ";
    console.log(text.length); // 14
    console.log(text.trim()); // "JavaScript"
    console.log(text.toUpperCase()); // "  JAVASCRIPT  "
Enter fullscreen mode Exit fullscreen mode

Top comments (0)