Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.now() function is used to return the timestamp of the current time. This method can be useful when working with animations in the browser.
Syntax:
_.now();
Parameters: It takes no parameters.
Returns: The return type is number.
Note: It is very necessary to link the underscore CDN before going and using underscore functions in the browser. When linking the underscore.js CDN The “_” is attached to the browser as a global variable.
Few examples are given below for a better understanding of the function.
Example 1:
<!DOCTYPE html> < html > < head > < script src = </ script > </ head > < body > < script > console.log(`Current timestamp is: ${_.now()}`) </ script > </ body > </ html > |
Output:
Example 2:
<!DOCTYPE html> <html> <head> <script src = </script> </head> <body> <script> //creating print function to print timestamp after delay of 10ms function print(){ setTimeout(()=>{ console.log(`Current timestamp is: ${_.now()}`) }, 10) } //running this function 5 times using _.times() function. _.times(5, print) console.log( "Type of timestamp is: " , typeof (_.now())) </script> </body> </html> |
Output: