How to Declare & Initialise a String in JavaScript

Steps:

  1. Declare a string variable using the var, let, or const keyword.
  2. Initialize the string variable with the desired value by enclosing the text in single or double quotes.

For example:

Javascript




// Declare and initialize a string
const myString = "Hello, World!";
 
// Print the string
console.log(myString);


Output

Hello, World!



How to Declare & Initialise a String in different Programming languages?

To declare and initialize a string in different programming languages, you can use language-specific syntax and functions. Below are examples in C++, C#, Python, JavaScript, and Java, with explanations for each language:

Similar Reads

How to Declare & Initialise a String in C++

Steps:...

How to Declare & Initialise a String in C#

...

How to Declare & Initialise a String in Python

...

How to Declare & Initialise a String in JavaScript

Steps:...

How to Declare & Initialise a String in Java

...