day05

//…day04 homework
function mean(a,b,c) {
return (a+b+c)/3
}

console.log(mean(1,2,3));

function mean(…args) {
let sum = 0;
for (let arg of args) {
sum = arg + sum
}
return sum /3
}

console.log(mean(1,2,3))

function mean(…args) {
return args.reduce((acc,val) => acc + val) / args.length;
}

console.log(mean(1,2,3))

function mean(…args) {
return args.filter(x => x%2 == 0).reduce((acc,val) => acc + val) / args.length;
}

console.log(mean(1,2,3,4))

//1.js
const b = 2
function greeting() {
const a = 1 + b
return ‘hi’
}
function sum(a,b,c){
console.log (arguments)
return a+b+c
}
sum(1,2,3)

console.log(this)

const person = {
name:“hzz”,
birthyear:“1999”,
calcAge:function(){
console.log(2020-this.birthyear)
}
}
person.calcAge();
const calculateAge = person.calcAge;
calculateAge();

let x = 10;
let y = 20;
function foo(z) {
let x = 100;
return x + y + z;
}
foo(30); // 150

let a = 20; //未初始化
const b = 30; //未初始化
var c; //undefined
function multiply(e, f) { // e = 20 , f = 30
var g = 20;
return e * f * g; // 203020=12000
}
c = multiply(20, 30);
console.log(a)
console.log(b)
console.log©

function multiply(e, f) { // e = 20 , f = 30
var g = 20;
return e * f * g; // 203020=12000
}
var c;

let a = 20;
const b = 30 ;
c =multiply(20,30)
console.log©

//全局EC:1.创建:1.this :全局对象
// 2.outer:null
// 3.ER : 1.
// 2.
// 3.
// 2. 执行
//函数EC:1.创建
// 2.执行

console.log(sayHello)
console.log(strMessage)
console.log(sayHi)
function sayHello() {
return ‘Hello, JavaScript!’
}
var strMessage = ‘Hello, Freshman!’
var sayHi = function () {
return ‘Hi, JavaScript’
}

//变量提升
console.log(a)
var a = ‘he’
console.log(a)

//let / const
function foo(){
console.log(a);
var a = ‘he’
console.log(a)
}
foo()

const name = “hzz”
const age = “21”
const city = “chengdu”

function getPersonInfo(){
const name =“hhhhh”
const age = 22

return `${name} is ${age} and lives in ${city}`

}
console.log(getPersonInfo)

const name = “Lydia”;
const age = 21;
const city = “chengdu”
function getPersonInfo() {
const name = “Sarah”;
const age = 22;
const city = “San Francisco”;
return ${name} is ${age} and lives in ${city};
}
console.log(${name} is ${age} and lives in ${city});

const age = 21
function checkAge() {
if (age < 21) {
const message = “You cannot drink!”
return message
} else {
const message = “You can drink!”
return message
}
}
//全局上下文中通过var声明的变量,会自动成为全局对象的属性;
//全局执行上下文通过函数声明定义的函数,会自动成为全局对象
let a = 1;
const b = 2;
var c = 3;

function foo(){
console.log(‘hi’)
}
const foo = function(){

}

//this绑定
var name =10
const foo = function () {
console.log(this.name + 10);
}
foo();

const foo = () => {console.log(2020-this.age)}
const foo = function(){
console.log(2020-this.age)
}
const oStudent = {
name : ‘hzz’,
age : ‘21’,
calcAge:foo
}
oStudent.calcAge();

let a = ‘Hello World!’;

function first() {
console.log(‘在 first 函数内’);
second();
console.log(‘再次在 first 函数内’);
}
function second() {
console.log(‘在 second 函数内’);
}
first();
console.log(‘在全局执行上下文中’);

let c = 2;
function foo(){
b = 1;
return ‘hi’ + c
}
foo()
console.log(b)

console.log(this)
function mean(){

}

const person = {
name: “peter”,
birthYear: 1999,
calcAge: function () {
console.log(2018 - this.birthYear);
}
};
person.calcAge();
// ‘this’ 指 ‘person’,因为 ‘calcAge’ 是通过用 ‘person’ 对象引用调用的。
const calculateAge = person.calcAge;
calculateAge();
// ‘this’ 指定全局对象,因为没有对象引用

// var a = 1;
// var b = 2;
// function foo(){

// }
// window
// a:1
// b:2
// foo:[function()]

let a = 20;
const b = 30;
var c;
function multiply(e, f) {
var g = 20;
return e * f * g;
}
c = multiply(20, 30);

function foo(){
var a
console.log(a)
a = 1
console.log(a)
}
foo(); //输出为undefined

const name = “Lydia”;
const age = 21;
const city = “San Francisco”;
function getPersonInfo() {
const name = “Sarah”;
const age = 22;
return ${name} is ${age} and lives in ${city};
}
console.log(getPersonInfo());

const name = “Lydia”;
const age = 21;
function getPersonInfo() {
const name = “Sarah”;
const age = 22;
const city = “San Francisco”;
return ${name} is ${age} and lives in ${city};
}
console.log(${name} is ${age} and lives in ${city});

const age = 21
function checkAge() {
if (age < 21) {
const message = “You cannot drink!”
return message
} else {
const message = “You can drink!”
return message
}
}

function foo(p1,p2){
console.log(p1+p2)
console.log(this);
}
foo(1,2);
foo.call(null,1,2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值