这段js代码是什么意思呀?

var start = Date.now();

var response = prompt("What is your name?", "");

var end = Date.now();

var elapsed = (end - start) / 1000;

document.write("You took " + elapsed + " seconds" + " to type: " + response);

https://img3.mukewang.com/5bff4e150001ad1905270100.jpg

为什么start和end都是Date.now()? 还有elapsed=(end-start)/1000是什么意思啊?

慕侠2389804
浏览 478回答 1
1回答

冉冉说

Date.now()都是取当前时间啊end和start执行的时间不同可以取出时间差得出花费了多少时间var start = Date.now();setTimeout(function(){    var end = Date.now();    console.log(end-start);},2000);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript