JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




Javascript Variable String


Tutorials Javascript

Topic

How can we use a string in javascript?
How to use the special characters '(quote), "(double quote), \(backslash), newline, tab in javascript string variable?



Explanation

String- E.g: "sdfesdfe"
For a variable to be a string type, the value assigned should be given in quotes.
A number given within quotes will be considered only as a string and not as an integer.
i.e if
var a = "2";
var b = "2";
then a+b will give "22" and not 4.


Special Character's: To use the special characters like tab, newline, back space, double quotes, etc.. in string variable the following format should be used

CharacterCode to be used
Single Quote\'
Double Quote\"
Backslash\\
Horizontal Tab\t
New Line\n
Back Space\b
Carriage Return\r

Example Code:
<script language="javascript">
var as = "this is \"a\" \'test\'";
document.write(as);
</script>


Result:
this is "a" 'test'





A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

Other Links

web hosting