zoukankan      html  css  js  c++  java
  • YDKJS读书笔记

    程序的本质就是语句的集合,只不过按照顺序进行排列了而已。

    语句包含表达式,表达式包含代码,程序由语句组成。

    interpreter,解释器;compiler,编译器;他们的职责就是对人友好的语句翻译成计算机能够理解的指令

    区别

    解释器:程序开始运行,由上到下,一行一行执行(点了菜,开始做菜,需等待一段时间才能吃上)

    编译器:程序还没执行,已经翻译成了计算机指令(还没点菜,菜已经做好,点了菜立马能吃上)

    常见的编程语言执行过程:

    JavaScript,python 解释器

    Java,C,C++ 编译器

    浏览器中使用console来书写并执行js代码,换行为shift+enter,enter即执行代码。

    在address bar输入about:blank来进行练习是一个好的习惯!

    coding(敲代码)是学习编程最好的方式。

     snippet 片段

    输出:

    学习建议使用console.log()语句,其中,console.是对象引用(object reference),log()是函数调用(function call)。

    输入:

    使用prompt(...)函数

    传入prompt()的信息将会在弹窗(popup)中打印出来。

    例如:

    age = prompt("please tell me your age: ");
    console.log(age);
    VM187:2 22
    

     用户输入的信息将会赋值给age变量,然后通过console.log(...);语句打印出来。

    Operators

    * 乘法操作符

    = 分配(assign)操作符,先计算=右边的表达式,然后将值赋给=左边的变量,这种操作的方式可能与通常的习惯相反,只能慢慢习惯他了。

    Here are some of the most common operators in JavaScript:
    
        Assignment: = as in a = 2.
    
        Math: + (addition), - (subtraction), * (multiplication), and / (division), as in a * 3.
    
        Compound Assignment: +=, -=, *=, and /= are compound operators that combine a math operation with assignment, as in a += 2 (same as a = a + 2).
    
        Increment/Decrement: ++ (increment), -- (decrement), as in a++ (similar to a = a + 1).
    
        Object Property Access: . as in console.log().
    
        Objects are values that hold other values at specific named locations called properties. obj.a means an object value called obj with a property of the name a. Properties can alternatively be accessed as obj["a"]. See Chapter 2.
    
        Equality: == (loose-equals), === (strict-equals), != (loose not-equals), !== (strict not-equals), as in a == b.
    
        See "Values & Types" and Chapter 2.
    
        Comparison: < (less than), > (greater than), <= (less than or loose-equals), >= (greater than or loose-equals), as in a <= b.
    
        See "Values & Types" and Chapter 2.
    
        Logical: && (and), || (or), as in a || b that selects either a or b.
    
        These operators are used to express compound conditionals (see "Conditionals"), like if either a or b is true.
    

     直接写在源代码中的值又叫做文字(literal)。  

    转换字符串为数字:

    c = Number(b)
    32

    转化数字为字符串:

    c = String(3)

    "3"comment(注释;评论)

    JavaScript的变量是属于动态类型,也就是说可以包含任何类型的值。

    implicitly coerce 暗中强制

    constants 常量

    a = 32.2341
    32.2341
    console.log(a.toFixed(3))
    VM293:1 32.234
    undefined

    toFixed(...)保留3位小数。

    const TAX_RATE = 0.08;

    var amount = 99.99;

    ES6中采用const来声明常量

    {...}区块,后面不需要接分号;

    loop 循环

    函数 代码section段

    multiple 多

    函数有范围这个概念,范围可以嵌套,比如范围A包括范围B,B可以使用A中的变量,但是A不能使用B中的变量。

    内部可以访问外部,外部不能访问内部。

    Only values have types in JavaScript; variables are just simple containers for those values.

    变量只是个容器,变量是没有类型这一说法的!变量包含的值才有类型。

    a = null;
    null
    typeof a
    "object"

    javascript的value types有以下七种:

    字符串、数字、布尔、undefined、null、object、symbol

    Built-in Type Methodswrapper forms 封装形式

    The specific list of "falsy" values in JavaScript is as follows:
    
        "" (empty string)
        0, -0, NaN (invalid number)
        null, undefined
        false
    
    Any value that's not on this "falsy" list is "truthy." Here are some examples of those:
    
        "hello"
        42
        true
        [ ], [ 1, "2", 3 ] (arrays)
        { }, { a: 42 } (objects)
        function foo() { .. } (functions)

    reserved words 保留字

    strict mode可以向下继承,但是不能向上继承。

    "use strict"

    不能省略var关键字

    执行函数的第二种方式

    (function IIFE(){
      console.log( "Hello!" );
    })();

    closure 闭合

    this不是指向函数本身,他是指向一个对象。

  • 相关阅读:
    TypeScript系列
    常用软件工具
    How to change Eclipse loading image
    【奥斯卡理财星体系 第五章】丨手把手教你从零开始搭建资产配置
    【奥斯卡理财星体系 第四章】丨你该如何选择适合的理财工具
    【奥斯卡理财星体系 第三章】丨你适合追求什么样的收益率
    ASP.NET Core使用Elasticsearch记录API请求响应日志实战演练
    C# Quartz.NET实现动态改变作业调度周期
    openssl 生成pfx
    netcore进程内(InProcess)托管和进程外(out-of-Process)托管
  • 原文地址:https://www.cnblogs.com/leomei91/p/7213815.html
Copyright © 2011-2022 走看看