Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Strings in JavaScript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 236
    Comment on it

    Hello Readers,

     

    JavaScript strings are used to store collection of characters or it can be text inside quotes. We can use both single and double quote. Lets talk about the basics of String.

     

    For Example :

     

    var userName = "Jonathan";
              OR
    var userName = 'Jonathan';

     

    If there is quotes inside a string then you need to insure that the quotes inside string don't match the quotes around the string.

     

    For Example :

     

    var userName = "My name is 'JONATHAN'";
    var userName = 'My name is "JONATHAN"';

     

    We can find the length of a string with JavaScript inbuilt property length.

     

    For Example :

     

    Var text = "My name is Jonathan"; // Result will be 13 it includes space also.

     

    If inside string quote is same or match with the quotes surrounding the string then we have \ escape character to get rid of this.

     

    For Example:

     

    var txt = "My name is "Jonathan""; // JavaScript misunderstand the string.
    

     

    In the above example JavaScript give you error. So to avoid this problem we can use escape character \.

     

    For Example:

     

    var txt = "My name is \"Jonathan\"."; //Escape Character turns in the string character.

     

    We can use escape character to insert other special characters in a string.

     

    For Example:

     

    \' //Insert single quote in a string.
    \" //Insert double quote in a string.
    \\ //Insert backslash in a string.
    \n //Use for new line.
    \t //Use for tab.
    \b //Use for backspace.

     

    This is the basic introduction of strings in JavaScript. Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: