JavaScript学习笔记(无体系)

本章主要参考来源:

W3C - JavaScript Tutorial

======================11.01=============================

  • document.write()
    <script>document.write(5 + 6);</script>
    The document.write() method should only be used for testing. because if you use document.write() after an HTML document is fully loaded, it will delete all existing HTML.
  • console.log()
    active the browser with F12.

======================11.03=============================

  • Variables
    declare a JavaScript variable with the var keyword

======================11.04=============================

  • Type Operator
    //Type operators are described in the JS Type Conversion chapter.
  • typeof
    Returns the type of a variable
  • instanceof
    Returns true if an object is an instance of an object type
  • assignment | 赋值?
    =、+=、-=、*=、/=
  • data type
    numbers, strings, arrays, objects and more(more?)
  • function
    a block of code designed to perform a particular task.

======================11.05=============================

  • object(被定义的对象)
  • Scope | 作用域?
    ** the set of variables, objects, and functions you have access to**
    <pre>// code here can not use carName
    function myFunction() {var carName = "Volvo"; // code here can use carName}</pre>
  • events
    <button onclick="this.innerHTML=Date()">The time is?</button>
  • strings
  • Numbers
    var x = 123;
    (100 + 23).valueOf(); // returns 123 from expression 100 + 23
    <br />
    x = "10 20"
    Number(x); // returns NaN

======================11.06=============================

  • math
  • math.
    document.getElementById("demo").innerHTML = Math.PI; // returns 3.141592653589793
  • Math.round(x) returns the value of x rounded to its nearest integer:
  • Math.pow(x,y) returns the value of x to the power of y:
  • Math.sqrt(x) returns the square root of x:
  • Math.abs(x) returns the absolute (positive) value of x:
  • Math.ceil(x) returns the value of x rounded up to its nearest integer:
  • Math.floor(x) returns the value of x rounded down to its nearest integer:
  • Math.sin(x) returns the sine (a value between -1 and 1) of the angle x (given in radians).
  • Math.min() and Math.max() can be used to find the lowest or highest value in a list of arguments:
  • random
    Math.random(); // returns a random number
  • date
    <pre>new Date() // current date and time
    new Date(milliseconds)
    new Date(dateString)
    new Date(year, month, day, hours, minutes, seconds, milliseconds)</pre>

======================11.07=============================

  • array
    var cars = ["Saab", "Volvo", "BMW"];

    var fruits = ["Banana", "Orange", "Apple", "Mango"];
    document.getElementById("demo").innerHTML = fruits.toString();
    //The toString() method returns an array as a comma separated string.
    
  • Booleans

  • Comparisons
  • Conditions

======================11.08=============================

  • Switch (like c++)
    switch (new Date().getDay()) {
    case 6:
    text = "Today is Saturday";
    break;
    case 0:
    text = "Today is Sunday";
    break;
    default:
    text = "Looking forward to the Weekend";}
  • loop
  • for
  • while

======================11.09=============================

  • RegExp(正则表达式)
  • errors
    try { Block of code to try}
    catch(err) { Block of code to handle errors}

======================11.10=============================

  • Hoisting(变量声明提升)
    var x; // Declare x
    x = 5; // Assign 5 to x

    elem = document.getElementById("demo"); // Find an element
    elem.innerHTML = x;                     // Display x in the element
    
  • Strict Mode
    "use strict";before the script statement
    ======================11.13=============================

  • Automatic Type Conversions?
    document.getElementById("demo").innerHTML = "Hello" - "Dolly";// returns NaN

======================11.15=============================

  • JSON——JavaScript Object Notation
    The JSON syntax is derived from JavaScript object notation syntax;
    JSON format is text only;
    Code for reading and generating JSON data can be written in any programming language.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 更多的在内容上注重细节处,做自己的观察者,这30天左右的坚持,我有过认真,有过努力,有过焦虑,有过欣喜,有过感伤,...
    华美人阅读 276评论 0 1
  • 对未来美好的预期,这是人类基因发展的结果。 生活在汶川的老百姓,是不是会天天心怀地震的恐惧呢?当然不会。如果担心的...
    瑞田学习力阅读 421评论 0 2
  • 01 出轨的本质是对情感与性的需要。有两种情况,一是自己积极交易的结果,二是他人拿出诱人的商品诱惑。 02 出轨是...
    小李有飞刀阅读 1,623评论 0 2