Hướng dẫn javascript cheat sheet github - javascript cheat sheet github

Bảng gian lận JavaScript

Dựa trên học X trong phút y.

JavaScript [JS] là một ngôn ngữ được giải thích năng động cung cấp năng lượng cho web. Nó được sử dụng rộng rãi trong các trình duyệt [trong đó các tập lệnh JS được giải thích bởi các công cụ JavaScript như V8 của Chrome] và ngày càng trên các máy chủ [trên môi trường thời gian chạy Node.js].

JS là ngôn ngữ kịch bản dựa trên nguyên mẫu với các hàm hạng nhất và gõ động. Do tính linh hoạt của nó, JS hỗ trợ nhiều kiểu lập trình bao gồm bắt buộc, hướng đối tượng và chức năng.

Đây là những gì tất cả những từ lớn ở trên có nghĩa là:

  • Ngôn ngữ được giải thích: Một ngôn ngữ [ví dụ: JS, Python] trong đó hầu hết các triển khai của nó thực hiện trực tiếp các hướng dẫn, mà trước đây không cần biên dịch chương trình thành các hướng dẫn bằng ngôn ngữ máy như các ngôn ngữ được biên dịch [ví dụ: C ++]: a language [eg. JS, Python] in which most of its implementations execute instructions directly, without previously compiling a program into machine-language instructions like compiled languages do [eg. C++]
  • JavaScript Engine: Một máy ảo diễn giải và thực thi JS: a virtual machine that interprets and executes JS
  • Dựa trên nguyên mẫu: Không giống như OOP cổ điển với các lớp và đối tượng, trong JS, các đối tượng được nhân bản từ các đối tượng khác và tất cả các đối tượng đều có nguyên mẫu [giống như mẫu mà chúng kế thừa]: unlike classical OOP with classes and objects, in JS, objects are cloned from other objects, and all objects have prototypes [kinda like the template they inherit from]
  • Các chức năng hạng nhất: JS hỗ trợ truyền các hàm làm đối số cho các hàm khác, trả lại chúng dưới dạng các giá trị từ các hàm khác và gán chúng cho các biến hoặc lưu trữ chúng trong cấu trúc dữ liệu: JS supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures
  • Được đánh máy động: "Loại" của tất cả các biến chỉ được giải thích tại thời gian chạy không giống như các ngôn ngữ được đánh máy tĩnh trong đó tất cả các biến có một loại tại thời điểm biên dịch: The "type" of all variables is only interpreted at run-time unlike statically typed languages where all variables have a type at compile-time
  • Lập trình bắt buộc: Lập trình dựa trên tuyên bố: Statement based programming
  • Lập trình hướng đối tượng: Lập trình dựa trên đối tượng: Object based programming
  • Lập trình chức năng: Lập trình dựa trên chức năng: Function based programming

Liên kết truy cập nhanh

  1. Điều cơ bản
    1. Nguyên thủy
    2. Người vận hành
  2. Cú pháp cơ bản hơn
    1. Biến
    2. Mảng
    3. Cấu trúc logic và kiểm soát
  3. Đối tượng và chức năng
    1. Các đối tượng
    2. Chức năng
    3. Bind, Gọi và áp dụng
  4. Thực thi chức năng, phạm vi biến, đóng & gọi lại
    1. Kéo
    2. Chuỗi phạm vi
    3. Đóng cửa
    4. Gọi lại
  5. JS định hướng đối tượng và kế thừa nguyên mẫu
    1. Người xây dựng
    2. Nguyên mẫu
    3. Kế thừa nguyên mẫu
    4. Nhà xây dựng tích hợp
  6. Lỗi và xử lý lỗi
  7. Công cụ ES6 mới

TODO: Thêm 8. Thư viện hữu ích [Lodash, JQuery], 9. JavaScript trong trình duyệt, 10. NodeJS

1. Những điều cơ bản

Mọi thứ trong JS đều là một đối tượng hoặc nguyên thủy. in JS is either an object or a primitive.

// This is a single line comment,
/* and this is a 
multiline comment */

// Semicolons [;] to terminate lines are optional
// However, the JS engine will [usually] automatically insert semicolons upon seeing '\n'
// This can cause some weird behaviour so ALWAYS use semicolons
doStuff[];

tôi. Nguyên thủy: số, chuỗi, boolean [và một số đặc biệt]

// JavaScript has one number type [which is a 64-bit IEEE 754 double].
// Doubles have a 52-bit mantissa, which is enough to store integers
//    up to about 9✕10¹⁵ precisely.
3; // = 3
1.5; // = 1.5

// Some basic arithmetic works as you'd expect.
1 + 1; // = 2
0.1 + 0.2; // = 0.30000000000000004 [funky floating point arithmetic--be careful!]
8 - 1; // = 7
10 * 2; // = 20
10 ** 2; // =100 [10 raised to the power 2] same as Math.pow[10, 2]
35 / 5; // = 7

// Including uneven division.
5 / 2; // = 2.5

// Bitwise operations also work; when you perform a bitwise operation your float
// is converted to a signed int *up to* 32 bits.
1 
"a" 
"a" 
"a" 
"a" 
"a" 
"a"  JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
1, khi được gọi nhiều lần, thực hiện một phần trình tạo tương ứng, dần dần tiến qua cơ thể cho đến khi từ khóa
// The `if` structure works as you'd expect.
var count = 1;
if [count === 3]{
    // evaluated if count is 3
} else if [count === 4]{
    // evaluated if count is 4
} else {
    // evaluated if it's not either 3 or 4
}

// As does `while`.
while [true]{
    // An infinite loop!
}

// Do-while loops are like while loops, except they always run at least once.
var input;
do {
    input = getInput[];
} while [!isValid[input]]

// The `for` loop is the same as C++ and Java:
// initialisation; continue condition; iteration.
for [var i = 0; i  JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
5 và thuộc tính
// They can be made literally:
var myObj = {key1: "Hello", key2: "World"};
// or using the Object constructor:
var myObj = new Object[];

// Keys are strings, but quotes aren't required if they're a valid
// JavaScript identifier. Values can be any type including other objects.
var myObj = {myKey: "myValue", "my other key": 4};

// Objects can even contain functions [called methods]
// When functions attached to an object are called, they can access the object
// they're attached to using the `this` keyword.
var myObj = { 
  name: "Destiny's Child",
  sayMyName: function[] {
    console.log[this.name];
  }
}
myObj.sayMyName[]; // outputs "Destiny's Child"

// Object attributes can also be accessed using the subscript syntax,
myObj["my other key"]; // = 4

// ... or using the dot syntax, provided the key is a valid identifier.
myObj.myKey; // = "myValue"

// Objects are mutable; values can be changed and new keys added.
myObj.myThirdKey = true;

// If you try to access a value that's not yet set, you'll get undefined.
myObj.myFourthKey; // = undefined

// iterating through objects
for[var property in myObj] { // do something }

// JSON [JavaScript Object Notation] is just a special case of Object literal notation
// where the keys are strings wrapped in quotes
var json_stuff = {
  "firstName": "John",
  "lastName": "Doe",
  "Age": 25
}

// JS Object => JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
6, miễn là phần thân của trình tạo tương ứng chưa
// They can be made literally:
var myObj = {key1: "Hello", key2: "World"};
// or using the Object constructor:
var myObj = new Object[];

// Keys are strings, but quotes aren't required if they're a valid
// JavaScript identifier. Values can be any type including other objects.
var myObj = {myKey: "myValue", "my other key": 4};

// Objects can even contain functions [called methods]
// When functions attached to an object are called, they can access the object
// they're attached to using the `this` keyword.
var myObj = { 
  name: "Destiny's Child",
  sayMyName: function[] {
    console.log[this.name];
  }
}
myObj.sayMyName[]; // outputs "Destiny's Child"

// Object attributes can also be accessed using the subscript syntax,
myObj["my other key"]; // = 4

// ... or using the dot syntax, provided the key is a valid identifier.
myObj.myKey; // = "myValue"

// Objects are mutable; values can be changed and new keys added.
myObj.myThirdKey = true;

// If you try to access a value that's not yet set, you'll get undefined.
myObj.myFourthKey; // = undefined

// iterating through objects
for[var property in myObj] { // do something }

// JSON [JavaScript Object Notation] is just a special case of Object literal notation
// where the keys are strings wrapped in quotes
var json_stuff = {
  "firstName": "John",
  "lastName": "Doe",
  "Age": 25
}

// JS Object => JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
7ed. Thuộc tính
// They can be made literally:
var myObj = {key1: "Hello", key2: "World"};
// or using the Object constructor:
var myObj = new Object[];

// Keys are strings, but quotes aren't required if they're a valid
// JavaScript identifier. Values can be any type including other objects.
var myObj = {myKey: "myValue", "my other key": 4};

// Objects can even contain functions [called methods]
// When functions attached to an object are called, they can access the object
// they're attached to using the `this` keyword.
var myObj = { 
  name: "Destiny's Child",
  sayMyName: function[] {
    console.log[this.name];
  }
}
myObj.sayMyName[]; // outputs "Destiny's Child"

// Object attributes can also be accessed using the subscript syntax,
myObj["my other key"]; // = 4

// ... or using the dot syntax, provided the key is a valid identifier.
myObj.myKey; // = "myValue"

// Objects are mutable; values can be changed and new keys added.
myObj.myThirdKey = true;

// If you try to access a value that's not yet set, you'll get undefined.
myObj.myFourthKey; // = undefined

// iterating through objects
for[var property in myObj] { // do something }

// JSON [JavaScript Object Notation] is just a special case of Object literal notation
// where the keys are strings wrapped in quotes
var json_stuff = {
  "firstName": "John",
  "lastName": "Doe",
  "Age": 25
}

// JS Object => JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
5 đề cập đến giá trị
// The `if` structure works as you'd expect.
var count = 1;
if [count === 3]{
    // evaluated if count is 3
} else if [count === 4]{
    // evaluated if count is 4
} else {
    // evaluated if it's not either 3 or 4
}

// As does `while`.
while [true]{
    // An infinite loop!
}

// Do-while loops are like while loops, except they always run at least once.
var input;
do {
    input = getInput[];
} while [!isValid[input]]

// The `for` loop is the same as C++ and Java:
// initialisation; continue condition; iteration.
for [var i = 0; i  JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
6 là
// JavaScript functions are declared with the `function` keyword.
// This is a function statement
function myFunction[thing]{
    return thing.toUpperCase[];
}

// This is a function expression
var makeUpperCase = function[] {
    return think.toUpperCase[];
}

// Note that the value to be returned must start on the same line as the
// `return` keyword, otherwise you'll always return `undefined` due to
// automatic semicolon insertion. Watch out for this when using Allman style.
function myFunction[]
{
    return //  JSON
JSON.stringify[myObj];

// JSON => JS Object
JSON.parse[json_stuff];
6 là
// JavaScript functions are declared with the `function` keyword.
// This is a function statement
function myFunction[thing]{
    return thing.toUpperCase[];
}

// This is a function expression
var makeUpperCase = function[] {
    return think.toUpperCase[];
}

// Note that the value to be returned must start on the same line as the
// `return` keyword, otherwise you'll always return `undefined` due to
// automatic semicolon insertion. Watch out for this when using Allman style.
function myFunction[]
{
    return // 

Bài Viết Liên Quan

Chủ Đề