当前位置:网站首页>Three ways and differences of defining functions in JS
Three ways and differences of defining functions in JS
2022-06-30 14:28:00 【Bamboo shrimp】
1、 Function declaration ( priority of use , It will be promoted when it is declared )
function fun(){
console.log('123');
}
fun()// Call the function name directly
2、 Function expression , Also called anonymous function ;
var fun = function(){
console.log('123');
}
fun()// Call anonymous functions , Use variable names plus ()
The process : This is defined by assigning a function to a variable , Function has no real name ; Since it's a variable , When making a statement , The function itself is not promoted , What is promoted is the variable name ;
3、 Self executing functions ( Do it yourself , And call yourself at the same time of declaration , It can only be called once )
(function()(
console.log('123')
})();
// principle : Evolved from a functional expression
The process : stay 2 in , hold fun(), Medium fun Directly replace with the function body , became function(){}(); Plus () Enclosed function body , lest js False positives are function declarations
边栏推荐
- Go language mutex lock
- 深入理解.Net中的线程同步之构造模式(二)内核模式4.内核模式构造物的总结
- 我想问一下招商证券怎么开户?通过链接办理股票开户安全吗
- Thoughts on the security of a PHP file name regular verification
- JMeter transaction controller
- V3 03_ Getting started
- About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)
- Comprehensively analyze the basic features and summary of free and paid SSH tools
- “即服务”,企业数字化转型的必然选择
- JS array
猜你喜欢
![[observation] as the intelligent industry accelerates, why should AI computing power take the lead?](/img/61/b446a616e86247507c27390505dc6b.jpg)
[observation] as the intelligent industry accelerates, why should AI computing power take the lead?

Thinkphp5 log file contains trick

Realize a simple LAN communication (similar to feiqiu)

ThinkPHP v3.2 comment annotation injection write shell

Rpm2rpm packaging steps

Step by step | help you easily submit Google play data security form

How to execute a query SQL

Notes on reverse learning in the first week of winter vacation

MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video

Pytoch viewing model parameter quantity and calculation quantity
随机推荐
Error on datetime when importing SQL file from MySQL
Zend studio how to import an existing project
Use PHP to delete the specified text content in the file
PHP recursive multi-level classification, infinite classification
MySQL back to table query optimization
Mysql database foundation: stored procedures and functions
Problems in QT creator (additional unknown and error lines are listed in the debug output window)
Small exercise of process and signal
[buuctf] [geek challenge 2019] secret file
Getting started with shell Basics
Why does the folder appear open in another program
Laravel upload error
【观察】智能产业加速,为何AI算力要先行?
This editor will open source soon!
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
KnightCTF WEB
Jetpack compose for perfect screen fit
Why is the resolution of the image generated by PHP GD library 96? How to change it to 72
Laravel8 custom log directory, rename
PHP common authentication / third-party methods