var getName = function () {console.log(3)};
function getName (){console.log(4)};
getName()//3function getName () {console.log(4)};
var getName = function (){console.log(3)};
getName() //依旧是3
大家讲道理2017-04-11 12:13:48
var getName = function () {console.log(3)}; //[1]
function getName (){console.log(4)};//[2]
getName()//3 [3]
function getName () {console.log(4)}; //[4]
var getName = function (){console.log(3)}; //[5]
getName() //依旧是3 [6]
==>
function getName (){console.log(4)};//[2]
function getName () {console.log(4)}; //[4]
var getName;//[1]
getName = function () {console.log(3)}; //[1]
getName();//3[3]
//var getName = function (){console.log(3)}; //[5] getName已经声明,var getName;被忽略
getName = function (){console.log(5)};//[5]
getName() //依旧是3 [6]
同名的变量名只申明一次,
变量声明和函数申明都会前提,但是函数申明比变量申明还要提前