Buy CSS Snippets

Just another WordPress site

  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 Strings 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?

One thought on “JavaScript String With Example And Latest Update?

  1. Wonderful work! This is the type of information that are meant to be shared across the web. Shame on Google for no longer positioning this post higher! Come on over and consult with my website . Thanks =)

Leave a Reply

Your email address will not be published. Required fields are marked *