1.y=y||’world’
function log(x,y){ y=y||’world’; console.log(x,y) } log(‘hello’)===>hello world log('hello','')==>hello world
2.y=y?y:'world'
function log(x,y){ y=y?y:'world'; console.log(x,y) } log('hello’)==>hello world log('hello','')==>hello world
3.传实参
function log(x,y='world'){ console.log(x,y) } log('hello')===> hello world log('hello','')==>hello