理解JS中的声明式与命令式?
声明式编程 :告诉机器你想要的是什么 让机器想出去做
优缺点 : 声明式减少了可变量(Immutable Variable)的声明,程序更为安全, 代码更加简洁 好的命名代码可读性更强
-
// 声明式
-
const numbers = [1,2,3,4,5]
-
const doubled = numbers.map (function (n) {
-
return n * 2
-
})
-
console.log (doubled) //=> [2,4,6,8,10]