QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Bitcoin BankingBuy, Sell, Store and Earn Interest
  • 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
    4 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
      3 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 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`.

Narayan Prusty

I am a full-stack web developer. I specialize in Blockchain and JavaScript. This is my personal blog where I write about programming and technologies that I learn and feel interesting to share.

5 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 Promise vs Callback
  • JavaScript Arrow “=>” Function
  • Stop requestAnimationFrame
Our Sponsor
Freelance: I am available
@narayanprusty
Hi, I am a full-stack developer - focusing on JavaScript, WordPress, Blockchain, DevOps, Serverless and Cordova. You can outsource your app development to me.





Will get back to you soon!!!
WordPress
ReactJS
Meteor
Blockchain
Serverless
Kubernetes
DevOps
DB & Storage
Ejabberd
Let's get started
My Books

2014 - 2015 © QNimate
All tutorials MIT license