HTML5—函数(传参、返回、条件判断、数组)
2018-06-19 本文已影响12人
一只小青蛙
变量预解析
var a; alert(a) 只把变量a的声明提前,赋值不提前,所以弹出undefined,表示它的值未定义
alert(c);报错,c没有声明,这是真正的未定义
函数预解析
myalert(); (弹出hello!)
function myalert(){ alert('hello!'); }
匿名函数:
有名字的函数:
window.onload = function(){
var oDiv = document.getElementById('div1');
oDiv.onclick = myalert;
function myalert(){
alert('hello'); }
匿名函数:
oDiv.onclick = function(){
alert('hello'); }