y=y||'world'与y=y?y:'world'
2017-02-21 16:06 改吧 阅读(681) 评论(0) 编辑 收藏 举报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