Name and Uses of 10 Javascript Inbuilt Functions

2.16K views
0
htmlAdmin2609 Changed status to publish October 6, 2020
Add a Comment
0

Javascript Inbuilt functions

About Javascript Inbuilt functions

JavaScript offers you to access a number of built-in features, including the prompt() function, which helps you to ask the consumer for written input. As with the confirm() function, you present a text prompt to ask the user to provide a value. On return, you set the output of the function equal to the prompt() function and use the data in your software.

  1. The functions are a reusable code-block that will be executed at any time when it’s called.
  2. It’s used for performing repetitive tasks where you can call the same function a number of times to get the same impact.
  3. The functions also use to validate user forms and alerts.

List of Javascript built-in functions

  1. parseFloat (string): If the string begins with a number, the function reads by way of the string till it finds the end of the number; cuts off the remainder of the string, and returns the end result. If the string doesn’t start with a number, the function returns NaN.
  2. length(): Returns the number of characters in the string and also returns the number of elements in the array.
  3. toString(): Outputs the value of the object as a string. This method is commonly used for display purposes.
  4. isNan(): Returns true, if the object isn’t a number or an illegal number and it returns False when the object is number.
  5. decodeURI(): Decodes a Uniform Resource Identifier Replaces every escape sequence within the encoded URI with the character that it represents, however, doesn’t decode escape sequences that might not have been launched by encodeURI. The character “#” will not be decoded from escape sequences.
  6. decodeURIComponent(): Replaces every escape sequence within the encoded URI component with the character that it represents. Its Decodes only a URI componentrather than the whole URI.
  7. encodeURI(): The function doesn’t encode characters that have particular meaning for a URI.
  8. Number(): The Number() function converts the object argument to a number and used to represent and manipulate numbers like 24If the value can’t be transformed to a legal number, NaN is returned.
  9. parseInt(): The ParsesInt() parses a string and returns an integer value.
  10. eval(): Returns the results of evaluating an arithmetic expression.
    Accepts a string that contains a script after which executes the string content as a script. Many developers use this function to create self-modifying functions that present good flexibility.
    Evaluated code runs extra slowly as a result of the browser can’t compile after which cache it.

Example: Create a User define function

User-defined function means you may create a function on your personal use. You’ll be able to create your self based on your want.

Syntax:

function functionName()
{
//Write Javascript Code Here;
}

Sample Code of javascript functions basic syntax: Javascript Function Declaration

function multiplyTwoNum()
{
N1 = document.getElementById(“textbox1”).value;
N2 = document.getElementById(“textbox2”).value;
document.getElementById(“showResult”).innerHTML = N1 * N2;
}

function divideTwoNum()
{
N1 = document.getElementById(“textbox1”).value;
N2 = document.getElementById(“textbox2”).value;
document.getElementById(“showResult”).innerHTML = N1 / N2;
}

function addTwoNum()
{
N1 = document.getElementById(“textbox1”).value;
N2 = document.getElementById(“textbox2”).value;
document.getElementById(“showResult”).innerHTML = N1 + N2;
}
function subTwoNum()
{
N1 = document.getElementById(“textbox1”).value;
N2 = document.getElementById(“textbox2”).value;
document.getElementById(“showResult”).innerHTML = N1 – N2;
}

Sample HTML Code and javascript inbuilt functions

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JavaScript program to calculate Addition, multiplication and division of two numbers | javascript inbuilt functions </title>
</head>
<body>
<form>
Input Number 1 : <input type=”text” id=”textbox1″ /><br>
Input Number 1 : <input type=”text” id=”textbox2″ /><br>
<input type=”button” onClick=”multiplyTwoNum()” Value=”Multiplication” />
<input type=”button” onClick=”divideTwoNum()” Value=”Divide” />
<input type=”button” onClick=”addTwoNum()” Value=”Addition” />

<input type=”button” onClick=”subTwoNum()” Value=”Addition” />
</form>
<p>The Result print here : <br>
<div id = “showResult”></div>
</p>
</body>
</html>

htmlAdmin2609 Changed status to publish October 6, 2020
Add a Comment
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.
close