Development| HTML| JavaScript| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
String Number Operations in JavaScript 
 

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

 

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>

                                       
              
 

 

                         

» View all related tutorials
Related Tags: java javascript html c table script delete object header method ip page oo create tab footer with e il it

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

this site is so good for the besics of java
i have one issue i.e is configure the weblogic
server in eclipse
i tried above issue but still i did not get the start of weblogic server through eclipse
i hope you people have excellent knowledge on eclipse tool as well weblogic server
so please send me the procedure of above issue to my mail id so that i should try once again through your procedure

Posted by hanumanthu on Tuesday, 07.29.08 @ 17:40pm | #69788

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

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  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.