Category: JavaScript

isNaN() Function in JavaScript

NaN stands for not a number in JavaScript.  Floats and integers are basically numbers.  IsNaN() function checks whether the value is number or not.  It will return true or false. This function will be helpful in case you want to avoid users from passing any value other than a number.   Example is given below where

String to Float Conversion in JavaScript

Floats are decimal numbers.  Similar to previous tutorial, if a float number is inside a quotation marks, it is treated as string by JavaScript.  To convert a string to float, we make use of parseFloat() function.  Example is given below. <html> <head> <title>JavaScript Tutorial </title> </head> <body> <script type="text/javascript"> var f1 = "1.35"; var f2

String to Integer Conversion in JavaScript

We have seen in previous tutorial that JavaScript treat a number as a string if you assign it using quotation marks.  Instead of addition of 2 numbers, it will perform concatenation.  To overcome this issue, we make use of parseInt() function in JavaScript.  This function will convert string to integer.  Example is given below. Note: 

String Concatenation in JavaScript

For string concatenation in JavaScript, we make use of plus (+) operator or concat function.  But the interesting part is, the plus (+) operator is also used for adding 2 numbers.  It all depends upon how you assign a value to a variable.  A string is always surrounded by quotes whereas a number does not

Comments in JavaScript

Comments in JavaScript are pretty much similar to PHP.  There are 2 types of comments, single-line comment and multi-line comment.  Single-line comment is useful in case of providing small information about the code.  Multi-line comment is useful in case of providing detailed information about the code.  Single-line comment starts with 2 forward slashes (//).  Multi-line