Blogger Information
Blog 87
fans 1
comment 0
visits 59167
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常用函数类型与常用数据类型的学习
阿杰
Original
476 people have browsed it

一、常用函数类型

(1)命名函数

  1. // 1.命名函数
  2. function firstName(name){
  3. return name;
  4. }
  5. console.log(firstName('小明'));

(2) 匿名函数

  1. // 2.匿名函数
  2. let getName = function(name){
  3. return 'Hello '+ name;
  4. }
  5. console.log(getName('张三'));

(3)立即调用函数

  • 即将声明与调用二合一
  1. // 立即调用函数
  2. console.log(
  3. (function(name){
  4. return 'Hello '+name;
  5. })('李四')
  6. );

(4) 箭头函数

  1. // 箭头函数
  2. test = (a,b) => {
  3. console.log(a + ' + ' + b +' = '+ (a+b))
  4. }
  5. test(3,4);

二、常用数据类型

(1)原始类型

  • number, string, boolean,undefined, null
  1. // 原始类型 number, string, boolean,undefined, null
  2. console.log(typeof 100);
  3. console.log(typeof 'hello');
  4. console.log(typeof true);
  5. console.log(typeof undefined);
  6. console.log(typeof null);

(2) 用类型

  • array, object, function
  1. // 引用类型 array, object, function
  2. const arr = [1, 'admin', [1, 2, 3], true];
  3. console.log(arr);
  4. let obj = { id:1, name:'王五',num:[1,2,3],isOk:true,'test name':'skdjf@qq.com'};
  5. console.log(obj.username+','+obj['test name']);
  6. function f1(callback) {
  7. console.log(callback());
  8. }
  9. f1(function() {
  10. return 'Hello 刘六';
  11. });

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post