What do return -1, 1, and 0 mean in this Javascript code?

后端 未结 3 1937
小鲜肉
小鲜肉 2021-02-01 10:29

Here is the context:

function compare (value1, value2) {
    if(value1 < value2) {
        return -1;
    } else if (value1 > value2) {
        return 1;
          


        
3条回答
  •  梦谈多话
    2021-02-01 11:06

    -1 means that value1 is less than value2

    0 means that value1 is equal to value2

    1 means that value1 is greater than value2

提交回复
热议问题