Mon Jul 25 2022
Most useful JavaScript built-in methods
Currently, JavaScript is the most popular high-level, dynamic, untyped, and interpreted programming language. As per recent reports of Github, JavaScript is almost twice more demanded than Python. It is one of the three core technologies of World Wide Web content production. The majority of websites employ it and it is supported by all modern Web browsers without plug-ins.
To utilize its power, JavaScript gives you access a number of built-in methods. Methods, that help you perform specific tasks with certain types of data. These methods make it easier to create robust applications for a programmer. In this geek story we'll highlight 10 most useful methods in JavaScript.
So, let's start
toLocaleString() - This method used to represent number object as human readable locale-specific string. Means, if the locale uses a comma for the decimal point, the viewer will see a comma, rather than a period, even if you use a period in the number.
search() - This method use for searching string by matching a regular expression and String object.
replace() - It used to find and replace on a string in JavaScript. This method finds a match between a regular expression and a string, then replaces those matches with a replacement. It returns a new string with matches of the string or regular expression replaced by any replacements made.
trim() - It used to removes any whitespace characters from both the beginning and ending of a particular string. This method is good for cleaning up data before operating on it.
encodeURI() - It encodes a string to use for a URI. It replaces all the whitespace and other non-URI character with their respective codes.
isNaN() - It used to determine whether a value is an illegal number or not. This method returns true if the given value equates to NaN (Not a Number), otherwise it returns false.
valueOf() - This JavaScript method used to return the primitive value of a String object as a string data type. It's required when in the situation where an object could cause problems.
map() - This is a very useful JavaScript method, that loops over every element in the array by executing a callback function on each item. it takes the results from each callback applied to each element, and returns those results in their entirety as an array.
random() - It used to returns a floating-point, pseudo-random number in the range between 0 (inclusive) and 1 (exclusive), which you can then scale to your desired range.
test() - This method search string for text that matches the regular expression. If it finds a match, then returns true, otherwise returns false.