Related Topics
Introduction
Html page 1
Html page 2
Html page3
Html page4
HTML Elements and structure
Html page 5
Html page 6
Html page 7
HTML Headings and Paragraphs
Html page 8
Html page 9
Html page 10
HTML Lists and Tables
Html page 11
Html page 12
Html page 13
HTML Forms and Input Fields
Html page 14
Html page 15
Html page 16
HTML Images and Media
Html page 17
Html page 18
HTML Links and Anchors
Html page 19
Html page 20
Html page 21
HTML Styles and Formatting
Html page 22
HTML Semantic Elements
Html page 23
Html page 24
HTML Attributes
Html page 25
Html page 26
HTML JavaScript Integration
Html page 27
Html page 28
Html page 29
Html page 30
HTML Document and Browser Support
Html page 31
Html page 32
HTML5 New Elements and Attributes
Html page 33
Html page 34
Html page 35
Html page 36
HTML Accessibility and Web Standards
Html page 37
Html page 38
Html page 39
HTML Responsive Design and Mobile Devices.
Html page 40
Html page 41
Html page 42
Introduction
Data Structure Page 1
Data Structure Page 2
Data Structure Page 3
Data Structure Page 4
Data Structure Page 5
Data Structure Page 6
Data Structure Page 7
Data Structure Page 8
String
Data Structure Page 9
Data Structure Page 10
Data Structure Page 11
Data Structure Page 12
Data Structure Page 13
Array
Data Structure Page 14
Data Structure Page 15
Data Structure Page 16
Data Structure Page 17
Data Structure Page 18
Linked List
Data Structure Page 19
Data Structure Page 20
Stack
Data Structure Page 21
Data Structure Page 22
Queue
Data Structure Page 23
Data Structure Page 24
Tree
Data Structure Page 25
Data Structure Page 26
Binary Tree
Data Structure Page 27
Data Structure Page 28
Heap
Data Structure Page 29
Data Structure Page 30
Graph
Data Structure Page 31
Data Structure Page 32
Searching Sorting
Data Structure Page 33
Hashing Collision
Data Structure Page 35
Data Structure Page 36

JAVASCRIPT
let message = 'Hello, world!';
let name = "John Doe";
let htmlTag = "<p>This is an HTML paragraph tag.</p>";
let specialChars = "This string contains \n a newline character \t and a tab character.";
Strings in JavaScript are immutable, which means that once a string is created, it cannot be changed. However, you can manipulate strings using various string methods to create new strings based on existing ones. Some common string methods include concat()
, toUpperCase()
, toLowerCase()
, substring()
, split()
, and many more.
For example:
let greeting = "Hello";
let name = "John";
let message = greeting.concat(", ", name, "!"); // Concatenating strings
console.log(message); // Output: "Hello, John!"
JavaScript provides a rich set of features and methods to work with strings, making it easy to manipulate and process textual data within your programs.
let message1 = 'This is a string using single quotes.';
Using double quotes:
let message2 = "This is a string using double quotes.";
Using backticks (also known as template literals):
let message3 = `This is a string using backticks.`;
All three declarations are valid and will create a string variable. You can choose the style that you find most readable or convenient for your specific use case.
It’s worth noting that template literals (backticks) have additional capabilities compared to single or double quotes. They allow for string interpolation, which means you can embed expressions or variables directly within the string using the ${}
syntax. For example:
let name = "John";
let greeting = `Hello, ${name}!`; // String interpolation
console.log(greeting); // Output: "Hello, John!"
Using string concatenation, you can combine multiple strings or string variables:
let part1 = "Hello";
let part2 = "world";
let message = part1 + ", " + part2 + "!"; // String concatenation
console.log(message); // Output: "Hello, world!"
Remember that strings are immutable, meaning their values cannot be changed once assigned. However, you can create new strings by manipulating existing ones using various string methods.
let str1 = "Hello";
let str2 = "world";
let message = str1 + ", " + str2 + "!"; // Concatenation using the + operator
console.log(message); // Output: "Hello, world!"
In the example above, the + operator is used to concatenate the strings str1
, ", "
, str2
, and "!"
together, resulting in the final string "Hello, world!"
.
2. Using the concat()
method:
let str1 = "Hello";
let str2 = "world";
let message = str1.concat(", ", str2, "!"); // Concatenation using the concat() method
console.log(message); // Output: "Hello, world!"
In this case, the concat()
method is called on str1
and passed ", "
, str2
, and "!"
as arguments. The method combines all the strings in the specified order and returns the concatenated string.
Both approaches achieve the same result, so you can choose the one that suits your coding style and preference. The concatenation operator (+) is more commonly used, while the concat()
method can be useful when concatenating multiple strings or when the order of concatenation needs to be more dynamic.
let greeting = "Hello";
let modifiedGreeting = greeting + ", world!";
console.log(greeting); // Output: "Hello"
console.log(modifiedGreeting); // Output: "Hello, world!"
In the example above, the original greeting
string remains unchanged even though it appears as if we appended ", world!"
to it. In reality, the +
operator creates a new string (modifiedGreeting
) by concatenating the original greeting
with ", world!"
. The original string remains intact and unaffected.
String immutability has important implications when working with strings in JavaScript. It means you cannot directly modify individual characters or substrings within a string. Instead, you need to create new strings by combining existing ones or using string manipulation methods.
For example, to convert a string to uppercase, you cannot modify the original string. Instead, you create a new string with the uppercase representation:
let text = "hello";
let uppercaseText = text.toUpperCase();
console.log(text); // Output: "hello"
console.log(uppercaseText); // Output: "HELLO"
The original text
remains unchanged, and a new string uppercaseText
is created with the modified content.
String immutability is an important concept in JavaScript and ensures the stability and predictability of string values. It also allows for efficient memory management and enables certain optimizations in the JavaScript engine.
let message = "Hello, world!";
let length = message.length;
console.log(length); // Output: 13
In the example above, the length
property is accessed on the message
string using dot notation (message.length
). The value of length
will be the number of characters in the string, which is 13 in this case.
It’s important to note that the length
property is a property, not a method, so it doesn’t require parentheses when accessing it.
The length
property is commonly used to perform operations or checks based on the length of a string. For example, you can use it in loops to iterate over each character in a string or use it to check if a string meets a certain length requirement.
let username = "john_doe";
if (username.length > 10) {
console.log("Username is too long.");
} else {
console.log("Username is valid.");
}
In the example above, the length
property is used to check if the username
string is longer than 10 characters and display an appropriate message based on the result.
By utilizing the length
property, you can easily determine the size of a string and use it in various scenarios within your JavaScript code.




Popular Category
Topics for You
Introduction
Html page 1
Html page 2
Html page3
Html page4
HTML Elements and structure
Html page 5
Html page 6
Html page 7
HTML Headings and Paragraphs
Html page 8
Html page 9
Html page 10
HTML Lists and Tables
Html page 11
Html page 12
Html page 13
HTML Forms and Input Fields
Html page 14
Html page 15
Html page 16
HTML Images and Media
Html page 17
Html page 18
HTML Links and Anchors
Html page 19
Html page 20
Html page 21
HTML Styles and Formatting
Html page 22
HTML Semantic Elements
Html page 23
Html page 24
HTML Attributes
Html page 25
Html page 26
HTML JavaScript Integration
Html page 27
Html page 28
Html page 29
Html page 30
HTML Document and Browser Support
Html page 31
Html page 32
HTML5 New Elements and Attributes
Html page 33
Html page 34
Html page 35
Html page 36
HTML Accessibility and Web Standards
Html page 37
Html page 38
Html page 39
HTML Responsive Design and Mobile Devices.
Html page 40
Html page 41
Html page 42
Introduction
Data Structure Page 1
Data Structure Page 2
Data Structure Page 3
Data Structure Page 4
Data Structure Page 5
Data Structure Page 6
Data Structure Page 7
Data Structure Page 8
String
Data Structure Page 9
Data Structure Page 10
Data Structure Page 11
Data Structure Page 12
Data Structure Page 13
Array
Data Structure Page 14
Data Structure Page 15
Data Structure Page 16
Data Structure Page 17
Data Structure Page 18
Linked List
Data Structure Page 19
Data Structure Page 20
Stack
Data Structure Page 21
Data Structure Page 22
Queue
Data Structure Page 23
Data Structure Page 24
Tree
Data Structure Page 25
Data Structure Page 26
Binary Tree
Data Structure Page 27
Data Structure Page 28
Heap
Data Structure Page 29
Data Structure Page 30
Graph
Data Structure Page 31
Data Structure Page 32
Searching Sorting
Data Structure Page 33
Hashing Collision
Data Structure Page 35
Data Structure Page 36
Go through our study material. Your Job is awaiting.