Explain Math.floor(Math.random())

前端 未结 6 1181
轻奢々
轻奢々 2020-12-19 07:52

I have seen many places using Math.floor() and Math.random()

like below

$(\'a.random-color\').hover(function() { //mouseove         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 08:07

    Math.random returns value between 0 and 1. You are multiplying it with 256 so it will return some float value between 0 and 256. math.floor will omit fraction value from it.

提交回复
热议问题