Javascript Variable String
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
| Character | Code to be used |
| Single Quote | ' |
| Double Quote | \" |
| Backslash | \ |
| Horizontal Tab | t |
| New Line | n |
| Back Space | b |
| Carriage Return | r |
Example:
<script language="javascript">
var as = "this is "a" 'test'";
document.write(as);
</script>
Result:
this is "a" 'test'