Home arrow JavaScript arrow Page 4 - JavaScript Statements

JavaScript Statements

In our last tutorial we covered where to place JavaScript code, how to work with variables, and print stupid things to the screen. In this installment we will be working with Conditional Statements, Switch Statements, and if there is time, Operators. So call up your date and cancel (who am I kidding? You'd rather go on a date than study this) and let's get to work.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
October 31, 2007
  1. · JavaScript Statements
  2. · If...Else
  3. · Switch Hitter
  4. · How to Enter Special Characters

print this article

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.



<script type="text/javascript">

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






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:



<script type="text/javascript">

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






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







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.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials