alert() |
It throws an alert box and is often used when user interaction is required to decide whether execution should proceed or not. |
alert("Let us proceed"); |
confirm() |
It throws a confirm box where user can click "OK" or "Cancel". If "OK" is clicked, the function returns "true", else returns "false". |
var decision = confirm("Shall we proceed?"); |
prompt() |
It produces a box where user can enter an input. The user input may be used for some processing later. This function takes parameter of type string which represents the label of the box. |
var userInput = prompt("Please enter your name:"); |
isNaN() |
This function checks if the data-type of given parameter is number or not. If number, it returns "false", else it returns ""true. |
isNaN(30); //falseisNaN(‘hello’); //true |
isFinite() |
It determines if the number given as parameter is a finite number. If the parameter value is NaN,positive infinity, or negative infinity, this method will return false, else will return true. |
isFinite(30); //trueisFinite(‘hello’); //false |
parseInt() |
This function parses string and returns an integer number |
parseInt("10"); //10
parseInt("10 20 30"); //10
parseInt("10 years"); //10
parseInt("years 10"); //NaN |
parseFloat() |
This function parses string and returns a float number |
parseFloat("10.34"); //10.34
parseFloat("10 20 30"); //10
parseFloat("10.50 years"); //10.50 |
eval() |
It takes an argument of type string which can be an expression, statement or sequence of statements and evaluates them. |
eval("var num1=2; var num2=3;var result= num1 * num2;console.log(result)"); |