QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads Generate Unique Number in JavaScript

Generate Unique Number in JavaScript

Here is the code that can generate a unique number in JavaScript.

function uniqueNumber() {
    var date = Date.now();
   
    if (date <= uniqueNumber.previous) {
        date = ++uniqueNumber.previous;
    } else {
        uniqueNumber.previous = date;
    }

    return date;
}

uniqueNumber.previous = 0;

function ID(){
  return uniqueNumber();
};

The ID() function will return a unique number every time you call.

Sep 30, 2015Narayan Prusty
JSON.parse() throws "unexpected token" error for valid JSONStreaming File Uploads to Storage Server with Node.js
Comments: 2
  1. MARV ALPERt
    5 years ago

    i want to give people a unique number. that unique number would be able to give them access to my website- to spin a wheel they could only use the number once.. do u have a javascript for that
    marvalpert@gmail.com

    ReplyCancel
    • Dotty
      5 years ago

      Before reading your article i don’t know the meaning of spam but after read it i know many useable things Thanks for posting such a nice arle2ti&#8c30;.

      ReplyCancel

Leave a Reply to MARV ALPERt Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

6 years ago 2 Comments Web Development
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • JavaScript Vibration API with Demo
  • JavaScript Limit Function Call Rate
  • JavaScript Arrow “=>” Function
  • JavaScript Promise vs Callback
  • Stop requestAnimationFrame
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license