Want to know what is function and how to use them in JavaScript? Just click here.
Every computer programming language has functions. Some functions are defined by the programmers while the code is being written while some functions are predefined when the language was built.
As every functions have three parts
- Function Declaration
- Function Definition.
- Function Call
In predefined functions, the first two points are already done inside the library which we include as a header file at the beginning of the program. we just have to call the function.
Few most common predefined functions that we use are:-
Functions to display something in JavaScript:-
alert(message) – It displays an alert box with a message specified in it.
confirm(message) – It will display the message with two buttons. “OK” and “Cancel”.
prompt(message) – Displays a box with the message passed. There the user can enter text in the prompt field, and choose OK or Cancel. If the user chooses OK, the string value entered in the field is returned and If the user chooses Cancel, a NULL value is returned.
Functions for conversion in JavaScript:-
parseFloat() – It returns floating-point numbers the same way as the parseInt function does, but looks for floating-point qualified strings and returns their value as afloat.
parseInt()– It converts a string to an integer returning the first integer encountered which is contained in the string. If no integer values are found such as in the string “written text”, then a value of 0 is returned.
Functions for comparison in JavaScript:-
eval()– Converts a string to integer or float value.
isNaN(value) – If the value passed is not a number, the boolean value of true is returned, if it is a number, it returns false.
escape(string) – It passes the string to be encoded and returns the encoded string. Encodes a string from ASCII into an ISO Latin-1 (ISO 8859-1) character set for HTML processing.
unescape() – Converts an ISO8859-1 character set to ASCII.
isFinite() – function determines whether the passed value is a finite number. If needed, the parameter is first converted to a number.
Functions for decoding and encoding in JavaScript:-
decodeURI()
function decodes a Uniform Resource Identifier (URI) previously created by encodeURI or by a similar routine. decodeURIComponent()
decodeURIComponent()
method decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent() or by a similar routine. encodeURI
encodeURI()
encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters). encodeURIComponent()
encodeURIComponent()
encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).
There are more predefined functions but these were the important ones which are often used.
Few important links for learning:-
- Let’s see an example for User form validation in JavaScript. click here.
- Let’s understand javascript. what and how? click here.
- Want to know what is function and how to use them in JavaScript? Just click here.
- Want to know what are variables and how to use them in JavaScript? Just click here.
Tagged : functions in javascript / javascript function / javascript function predefined / Predefined Functions / Predefined Functions in JavaScript