Home arrow JavaScript arrow Page 2 - JavaScript Objects: Strings
JAVASCRIPT

JavaScript Objects: Strings


In our last tutorial we covered JavaScript Errors. We learned to work with the OnError event, the Try...Catch statement, and Throw to create exceptions. In this episode we will go over JavaScript String Objects and learn to use them.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
January 14, 2008
TABLE OF CONTENTS:
  1. · JavaScript Objects: Strings
  2. · Length Property
  3. · Prototype
  4. · The Anchor() Method
  5. · The Big() Method
  6. · The Bold() Method

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
JavaScript Objects: Strings - Length Property
(Page 2 of 6 )

The length property returns the number of characters in a string. Pretty simple. Here it is used in code:


<html>

<body>

<p>COMPUTAR R SMARTE IT TELL NUMBER OF PERTY LETERS:<br /><br /></p>

<script type="text/javascript">


var longword="Look how long this string is weeeeeeeee!"

document.write(longword.length)


</script>


</body>

</html>

This code would display:

  COMPUTAR R SMARTE IT TELL NUMBER OF PERTY LETERS:

  40

Note that the Length also includes the number of spaces in the string.

In this example we will create two variables with words in them, display the number of characters in each word, then display how many more letters the larger word has than the smaller word:

 

<html>

<body>

<p>COMPUTAR R SMARTE IT TELL NUMBER OF PERTY LETERS:<br /><br /></p>

<script type="text/javascript">


var longword="Googleplex"

var shortword="Cat"

document.write("The word Googleplex has this many letters: ")


document.write(longword.length)


document.write("<br />The word Cat has this many letters: ")

document.write(shortword.length)

document.write("<br />Googleplex has this many more letters: ")

document.write(longword.length - shortword.length)

</script>


</body>

</html>

This will result in the following print out:

  COMPUTAR R SMARTE IT TELL NUMBER OF PERTY LETERS:

  The word Googleplex has this many letters: 10
  The word Cat has this many letters: 3
  Googleplex has this many more letters: 7


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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