Use functional numeric face quantity and functional declaration to declare two functions of the same name at the same time, why does the result only execute the function of function numeric face quantity declaration?

question:

var getName = function(){alert(1)};
function getName(){alert(2)};

getName();// 1

or

function getName(){alert(2)};
var getName = function(){alert(1)};

getName();// 1

Why?

Jun.09,2021

first the function is declared in advance
is equivalent to first declaring the getName function and then getName overwriting


1. Declarative functions are declared and defined in advance
2. During execution, you can reassign


var getName = function(){alert(1)};
function getName(){alert(2)};

getName();// 1

it can be understood that the above part is pre-processed.

var getName;
function getName(){alert(2)};

getName = function(){alert(1)};
getName();// 1

the test example is

getName();
function getName(){alert(2)};

the second can be understood as, again, the first part is pre-processing.

function getName(){alert(2)};
var getName;

getName = function(){alert(1)};
getName();// 1

that's why it's always 1

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39c55-2c1c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39c55-2c1c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?