How to Declare & Initialise a String in JavaScript
Steps:
- Declare a string variable using the
var
,let
, orconst
keyword. - 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: