5.08.2016

Javascript string object



Javascript string object

Javascript strings are used for storing, manipulation, formatting and determine the location of substring within strings i.e. it stores the character like ”how I set”. Generally, a string is kept inside the quotes and both single and double quotes can be used, it does not matter much.


Simple  example of JS

<!DOCTYPE html>
<html>
<body>
<p id="intro"></p>
<script>

var name1 = "dev";
var name2 = 'giri';

document.getElementById("intro").innerHTML =

name1 + "\t" + name2; 
</script>
</body>
</html>

Special character



Generally string are written under the quotes. To avoid misunderstanding, javascript uses the special character for the dynamic result.


Some special character are listed here:



Code         output
\’                single quote
\”               double quotes
\\                backslash
\n               new line
\r                carriage return
\t                tab
\b               backspace
\f                form feed


 Most common method of javascript 


String length:- length is the built in property of javascript. It return the number of character in the string.
Example:
<!DOCTYPE html>
<html>
<body>
<p id="number"></p>
<script>
var txt="i am in howiset.blogspot.com webpage";
document.getElementById("number").innerHTML =
txt.length;
</script>
</body>
</html>




Stay happy with www.howiset.blogspot.com



 



No comments:

Post a Comment