JavaScript
  Home arrow JavaScript arrow Page 4 - JavaScript Statements
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JavaScript Statements
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-10-31

    Table of Contents:
  • JavaScript Statements
  • If...Else
  • Switch Hitter
  • How to Enter Special Characters

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    JavaScript Statements - How to Enter Special Characters


    (Page 4 of 4 )

    Before we go any further we should discuss the role of special characters in JavaScript. Special characters include apostrophes, new lines, double and single quotes, the ampersand, etc.

    To insert any of those in JavaScript, you need to use the (/) backslash key.


    <html>

    <body>

    <script type="text/javascript">

    var description = “The Wookie said, “Rawr” and stabbed me.”

    document.write(description)

    }

    </script>

    </body>

    </html>

    I know, Wookies don't say Rawr. If anyone wants to take the time to spell the sound a Wookie makes, I will be glad to add it to the code. Until then though, good ole Chewbacca says Rawr.

    Since Javascript reads double and single quotes as the beginning and end of a string, the above code would have caused this to print:

      The Wookie said,

    That's obviously not what we had intended. If left like that, millions of Star Wars nerds would be riveted to their seats, waiting to find out exactly what that giant Ewok really had to say. Which is fine really, because what else do they have to do?

    To remedy this particular situation, we would simply input the backslash (/) into our code. Like this:


    <html>

    <body>

    <script type="text/javascript">

    var description = “The Wookie said, /“Rawr/” and stabbed me.”

    document.write(description)

    }

    </script>

    </body>

    </html>

    This would cause the following to print out:

      The Wookie said, “Rawr” and stabbed me.

    The backslash goes before each quote, transforming them into a string literal.

    Below is a list of how to handle other special characters:


    • ' : Outputs a single quote.

    • ” : Outputs a double quote.

    • & : Outputs an ampersand

    • : Outputs a backslash

    • n : Outputs a new line

    • r : Outputs a carriage return

    • t : Outputs a tab

    • b :Outputs a backspace

    • f : Outputs a form feed

    Before we say goodbye, I want to show you a big table full of operators. You can study it before our next tutorial if you like.

    Arithmetic Operators

     

    Operator Symbol

    What it Does

    +

    Used for addition

    -

    Used for subtraction

    *

    Used for multiplication

    /

    Used for division

    %

    Returns the remainder in division

    ++

    Increments a value by 1

    --

    Decrements a value by 1

    Assignment Operators

     

    Operator Symbol

    What it Does

    =”

    Assigns a value to a variable

    +=

    Assigns and adds a value

    -=

    Assigns and subtracts a value

    *=

    Assigns and multiplies a value

    /=

    Assigns and divides a value

    %=

    Assigns and Modulates a value

    Comparison Operators

     

    Operator Symbol

    What it Does

    ==”

    Is equal to

    ===”

    Is equal to both value and type

    !=

    Not equal to

    >

    Greater than

    <

    Less than

    >=

    Greater than or Equal To

    <=

    Less than or Equal To

    Logical Operators

     

    Operator Symbol

    What it Does

    &&

    AND

    ||

    OR

    !

    NOT

    That's it for this episode. In the next article we will talk more about Operators and how to manipulate data with the, learn how to work with Functions, and maybe even cover Functions.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thanks for dropping by the read my article on Javascript. In this exciting episode...
     

    JAVASCRIPT ARTICLES

    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway