Monday, July 27, 2026
HomeLanguagesJavascriptUnderscore.js _.now() function

Underscore.js _.now() function

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:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS