Loading

String

  • In JavaScript, Strings are sequences of characters enclosed in single (''), double ("") quotes, or backticks (``).

ways to create a String:

  • String Literal
  • String Object(new keyword)

String Literal

  • You can create strings using single quotes, double quotes, or backticks for template literals.

Syntax:

var stringname="string value";  

Example:

<!DOCTYPE html>
<html>

<body>
  <script>
    var str = "Welcome to Quipoin";
    document.write(str);  
  </script>
</body>

</html>

Output:

Welcome to Quipoin


String Object(new keyword)

Syntax:

var stringname=new String("string literal");  
  • new keyword is used to create an instance of string.

Example:

<!DOCTYPE html>
<html>

<body>
  <script>
    var stringname = new String("hello javascript string");
    document.write(stringname);  
  </script>
</body>

</html>

Output:

hello javascript string