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

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

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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