JavaScript Builtin Functions

Built-in Functions :

JavaScript comes with some built-in functions. To use them, we just need to invoke them.

Let us explore some of these built-in functions to understand their significance and usage.

Built-in functions Description Syntax
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); //false
isNaN(‘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); //true
isFinite(‘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)");

JavaScript provides two-timer built-in functions. Let us explore these timer functions.

Function Name Description Code Snippet
setTimeout() It executes a given function after waiting for the specified number of milliseconds.
It takes 2 parameters. First is function to be executed and second is number of milliseconds after which given function should be executed.
function executeMe(){ colsole.log(“Function says hello!”) } setTimeout(executeMe, 3000); //It executes executeMe() after 3 seconds.
setInterval() It executes the given function repetitively. It takes 2 parameters, first is function to be executed and second is the number of milliseconds. Function executes continuously after every given number of milliseconds. function executeMe(){ console.log(“Function says hello!”); } setInterval(executeMe,3000); //It executes executeMe() every 3 seconds
#javascript_built_in_functions #Built-in_Functions_in_Javascript #javascript_inbuilt_functions #javascript_built_in_functions_with_examples #javascript_built_in_functions_list_

(New page will open, for Comment)

Not yet commented...