Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

String Number Operations in JavaScript

                         

In this article you learn the basics of JavaScript and create your first JavaScript program.

 What is String Number Operation?
The JavaScript  String is a loosely type language. This is not mean that it has no data types that the value of a variable or a JavaScript object property does not need to have a particular type of the value assigned, or that it should be always hold the same type of value. JavaScript also freely type-converts values into a type require by the context of their use. JavaScript being is the loosely typed and willing to type-convert still does not save the programmer from need to the think about the actual type of values that they are dealing with. A very common error in browser  scripting. for example, it is to read the value property of a form control into which the user is expected to type a number and then add that value to another number. Because the value properties of form controls are strings if the even then character is sequence they contain represents a number of the attempt to add that string to a value, even if the value happens to be a number, results in the second value being type-converted into a string and concatenated to the end of the first string value from the from control. The problem arises from dual nature of the + operator used for the both numeric addition and string concatenation. which the nature of the operation performed is determined by the context, where only both the operation are numbers to start with the + operator perform addition. Otherwise it converts all of its operands to strings and does concatenation. 

Converting String:
The String most often from the action + Operators. when one of its operators not a number. The easy way of getting the string that results from type-conversion is to concatenate a value to string. The alternative method of convert a value into a string to pass it is argument to the String constructor called as a function. Exam:-

                             Var string Value= String(d);

Converting Number:
The Converting values to numbers especially to strings numbers, it is an extremely common requirement and many methods can be used. There are any mathematical operation except the concatenation addition operator will force type-conversion. So the conversion of a string to a number might entail performing a mathematical operation on the string representation of the number that would not affect the resulting number, such as subtracting zero or multiplying by one.

var numValue = stringValue - 0; 
var numValue = stringValue * 1;
var numValue = stringValue / 1;

String in JavaScript
The JavaScript language until now we have been focusing on the language constructs of JavaScript: if statements, loops, functions, etc. This primer are going to take a step back and cover the inner workings of some of the native JavaScript objects: Strings, Numbers and Arrays. 

Example:

<html>
<head>
<Script language="JavaScript">
document.write(' Test'.indexOf('T')); 
document.write('This '.lastIndexOf('T')); 
document.write('This is test'.charAt(10)); 
document.write('This program Test'.length); 
document.write(' program'.substring(1, 10)); 
document.write('my exam Test'.substr(7, 10)); 
document.write('my program'.toUpperCase()); 
document.write(' first JavaScript program'.toLowerCase()); 
document.write("<br />")
</script>
</table>
</body>
</html>

 

Array in JavaScript
Array is the basically just a list of items. Each item an array can be whatever you want, but they are usually related to one-another.

Example:

 <html>
<head>
<script language="JavaScript">
var students = ['amar', 'rani', 'vinod', 'susil','santosh'];
var suffixes = ['1st', '2nd', '3rd', '4th','5th'];
for(var i=0; i<=4; i++)

alert('The '+suffixes[i]+' student is '+students[i]);
}
</script>
</head>
</body>
</html>

JavaScript in Number Operation
The numbers is a central task for the many programs. In fact, the desire to automate number operations was the motivation that drove the invention of digital computers decades ago. we will learn how to work with numbers in Java, including arithmetic, conversions, and other numeric operations. 

Example:
    

<html>
<head>
<Script language="JavaScript">
var sum = 10 + 10;
sub = 15 - 5;
mul = 25 * 5; //multiplication
divided = 30 / 5;
modulus = 10 % 10; //modulus division
document.write("sum:"+sum); 
document.write("sub:"+sub);
document.write("mul:"+mul); 
document.write("divided:"+divided);
document.write("modulus:"+modulus); 
</script>
</head>
</body>
</html>

                                       
              
 

 

                         

Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.