JavaScript函数写法整理
2024-08-30 22:06:37
1.普通函数定义的两种写法
function hello(){
console.log("hello!");
} var hello = function(){
console.log("hello!");
}
2.函数自执行,快速初始化变量(两种写法hello变量值为15)
#函数自执行
var hello = function(num){
return 3 * num;
}(5); #普通写法
var hello = 5;
hello = 3 * hello;
3.函数预执行
(function(){
console.log('Hello ');
})();
4.闭包
function say(name){
var info = 'Hello ' + name;
return function(){
console.log(info);
}
}
var s= say('bret');
s();
最新文章
- java面试知识(来自牛客网)
- awk的涂鸦
- 每天一个linux命令(7):mv命令
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
- oGrid 介绍如何从 server 取的资料
- Javascript 笔记与总结(2-17)事件委托
- linux 相关系列安装
- vim配置php开发环境
- MySQL存储过程之事务管理
- WPF拖到、移动控件
- 输出内容(document.write)四种写法
- Rabbitmq中rabbitmqctl的常用命令
- Redis教程03——Redis 发布/订阅(Pub/Sub)
- IT项目经理
- java如何把char型数据转换成int型数据(转)
- HDU 5558 后缀数组+二分
- HDFS概述(4)————HDFS权限
- 目标检测算法之Faster R-CNN算法详解
- 浏览器JS报错Uncaught RangeError Maximum call stack size exceeded
- C# SetParent将其他程序嵌入自己的程序
热门文章
- 小程序(Wepy)--生成海报图片
- BZOJ 1396 识别子串 (后缀自动机+线段树)
- nfs+inotify
- 集成spring boot + mysql + docker实战
- 常用js方法封装
- 【转载】linux下的usb抓包方法
- Android知识点总结
- 手写一个节点大小平衡树(SBT)模板,留着用
- NHibernate3剖析:Query篇之NHibernate.Linq增强查询
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com