program Structure

本文介绍了JavaScript中的变量声明方式,包括let、var和const等关键字的使用。同时深入探讨了环境(Environment)、函数(Function)以及控制流(Control flow)的概念,并且讲解了如何使用箭头函数和可选参数等功能来提高代码效率。此外,还涉及到了数据结构如对象和数组的操作方法。

BINDINGS or variables 

    keyword: let, var, const:

BINDING NAMES: 

        A binding name may include dollar signs ($) or underscores (_) but no other

    punctuation or special characters.

ENVIRONMENT:

        The collection of bindings and their values that exist at a given time is called
    the
environment. When a program starts up, this environment is not empty. It
    always contains bindings that are part of the language standard, and most of the
    time, it also has bindings that provide ways to interact with the surrounding
    system. For example, in a browser, there are functions to interact with the
    currently loaded website and to read mouse and keyboard input.


FUNCTIONS:

    A function is a piece of program wrapped in a value .

Control flow :

    C类似: if whiel, do-while, for-loops, break, continue, switch-case

Functions as values

    let launchMissiles = function() {
        missileSystem.launch("now");
    }; 

    Declaration notation (没有顺序)

    function square(x) {
        return x * x;
    } 

Arrow functions

    const square1 = (x) => { return x * x; };

Optional Arguments

    function minus(a, b) {
    if (b === undefined) return -a;
        else return a - b;
    }

 Rest parameters 

 function max(...numbers) {

        let result = -Infinity;
        for (let number of numbers) {
        if (number > result) result = number;
        }
            return result;
        }
    console.log(max(4, 1, 9, -2));
    // → 9 

function power(base, exponent = 2) {

    let result = 1;
    for (let count = 0; count < exponent; count++) {
        result *= base;
    }
        return result;
    } 


Data Structures: Objects and Arrays

let anObject = {left: 1, right: 2};
console.log(anObject.left);
// → 1
delete anObject.left;
console.log(anObject.left);
// → undefined
console.log("left" in anObject);
// → false
console.log("right" in anObject);
// → true 

console.log(Object.keys({x: 0, y: 0, z: 2}));
// → ["x", "y", "z"] 

let objectA = {a: 1, b: 2};
Object.assign(objectA, {b: 3, c: 4});
console.log(objectA);
// → {a: 1, b: 3, c: 4} 


mutability:

对象的比较是对象id的比较,类似python对象 is 比较

Number , string,  boolen, 内置数据类型不可变,

let kim = "Kim";
kim.age = 88;
console.log(kim.age);
// → undefined 

DESTRUCTURE

function phi(table) {
return (table[3] * table[0] - table[2] * table[1]) /
Math.sqrt((table[2] + table[3]) *
(table[0] + table[1]) *
(table[1] + table[3]) *
(table[0] + table[2]));
} 

function phi([n00, n01, n10, n11]) {
return (n11 * n00 - n10 * n01) /
Math.sqrt((n10 + n11) * (n00 + n01) *
(n01 + n11) * (n00 + n10));
} 

JSON

JSON.stringify(object) , JSON.parse(string)







    

 



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值