DEV Community

Jaisurya
Jaisurya

Posted on

JavaScript Strings

A string in JavaScript is a sequence of characters used to represent text. Strings can contain letters, numbers, spaces, symbol, and special characters.

Creating strings in JavaScript

JavaScript provides multiple ways to create strings. A string can be enclosed within single quotes (''), double quotes (""), or backticks (``). All three approaches create string values, but template literals offer additional feature such as string interpolation and multi-line strings.

Syntax

`javascript
let stringName = "string value";

`
Here:

  • let is used to declare the string variable.
  • stringName represents the name of the string variable.
  • "string value" is the text stored in the string. Example

`javascript
let message = "Welcome to Dev Community";
console.log(message);

//Output : Welcome to Dev Community

`

Explanation:

In the above example, we created a string variable named message and assigned a text value to it. The value is then displayed using the console.log() method.

Top comments (0)