String is
a collection of characters. Unlike other languages, JavaScript don’t have any
data type to represent character.
How to define a string?
Enclose
collection of characters in single quotes (or) double quotes.
var str1 =
"Hello World";
var str2 =
'Hello World';
You can
also create string by using String object.
var str3 =
new String("Hello World");
string.html
<!DOCTYPE html> <html> <head> <title>strings</title> </head> <body> <script type="text/javascript"> var str1 = "Good Morning"; var str2 = 'Good Afternoon'; var str3 = new String("Good Night"); document.write(str1 + "<br />"); document.write(str2 + "<br />"); document.write(str3 + "<br />"); </script> </body> </html>
How the string in JavaScript is
different from other languages?
All
strings are Unicode internally.
No comments:
Post a Comment