1. Home
  2. /
  3. JavaScript Tutorial
  4. /
  5. JavaScript String With Example And Latest Update?

JavaScript String With Example And Latest Update?

In this tutorial, we will learn how to Create and Manipulate String in JavaScript.

Introduction to JavaScript String

The string is like an object. You can store multiple texts in a JavaScript string. In this, along with characters, you can also show numbers as a string inside quotes(” “). You can also use strings from the single quote or double-quotes.

What is String in JavaScript

JavaScript String There is an object inside which you can include a sequence of letters (AZ, a-z), numbers (0,9), special characters (!” #$), and arithmetic values ​​or a combination thereof. String object inside JavaScript, single quotes (') or double quotes ("), you can create.

See in the example given below, in which the String object has been defined using single quotes and double-quotes.

Also Read: What are JavaScript Data Types?

JavaScript String With Example And Latest Update
JavaScript String With Example And Latest Update

JavaScript Single And Double quotes Example | How do you write a single quote or double quotes in JavaScript?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>How to declare String Object In JavaScript In Hindi</title>
</head>
<body>
    <script>
    // Creating variables
    var myString = 'Hello topfaida'; // Single quoted string
    var myString = "Hello topfaida!"; // Double quoted string
    
    // Printing variable values
    document.write(myString + "<br>");
    document.write(myString);
    </script>
</body>
</html>

You can also add different Quotes inside the JavaScript String Object. That is, if you have used Single Quotes with String Object, then you can use Double Quotes inside Single Quotes and if you have used Double Quotes then you can use Single Quotes.

Also Read: What are HTML Tags? | Understand the HTML Tags?

See in the example given below, in which Double Quotes have been used inside the Object of Single Quotes and Single Quotes have been used inside Double Quotes.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JavaScript Strings Example  </title>
</head>
<body>
    <script>
    // Creating variables
    var str1 = "it's okay";
    var str2 = 'He said "see you tomorrow"';
    var str3 = "She said 'don't cry, please'";
    
    // Printing variable values
    document.write(str1 + "<br>");
    document.write(str2 + "<br>");
    document.write(str3);
    </script>
</body>
</html>

But, still, you want to use single quotes with String Object and use of double quotes with double quotes, so in this case, you have to use the backslash character () has to be used.

Let us see through example.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Escaping Quotes Example inside JavaScript Strings In Hindi</title>
</head>
<body>
    <script>
    // Creating variables
    var str1 = 'it's okay';
    var str2 = "He said "see you tomorrow"";
    var str3 = 'She replied 'don't cry, please'';
    
    // Printing variable values
    document.write(str1 + "<br>");
    document.write(str2 + "<br>");
    document.write(str3);
    </script>
</body>
</html>

Also Read: How to add CSS in HTML?

What is JavaScript code called?

JavaScript is a dynamic computer programming language. JavaScript code is coded along with the HTML page. JavaScript provides programming facilities to web designers and it is very useful for a web designer to have knowledge of JavaScript.

Which is the correct way to construct a string in Javascript?

join(‘ ‘) + ‘ ‘; I won’t bore you with benchmarks; You just have to trust me (or test it yourself) – it’s by far the fastest way!

What is the original name of JavaScript?

The actual name of JavaScript is “ECMAScript”.

Leave a Reply

Your email address will not be published.