JavaScript チートシート

王林
リリース: 2024-08-08 03:41:12
オリジナル
1334 人が閲覧しました

JavaScript Cheat Sheets

Hey everyone! I've got some great news for all you beginners learning JavaScript! A quick reference guide for JavaScript is now available! You can easily check important concepts, functions, and methods right away. For more details about the guide, check it out here.

What's in the Quick Reference Guide

Console

// => Hello world!
console.log("Hello world!");

// => Hello CheatSheets.zip
console.warn("hello %s", "CheatSheets.zip");

// Output error message to standard error
console.error(new Error("Oops!"));
ログイン後にコピー

Numbers

let amount = 6;
let price = 4.99;
ログイン後にコピー

Variables

let x = null;
let name = "Tammy";
const found = false;

// => Tammy, false, null
console.log(name, found, x);

var a;
console.log(a); // => undefined
ログイン後にコピー

Strings

let single = "Wheres my bandit hat?";
let double = "Wheres my bandit hat?";

// => 21
console.log(single.length);
ログイン後にコピー

Arithmetic Operators

5 + 5 = 10     // Addition
10 - 5 = 5     // Subtraction
5 * 10 = 50    // Multiplication
10 / 5 = 2     // Division
10 % 5 = 0     // Modulus
ログイン後にコピー

Comments

// This is a comment

/*
You need to change this setting
before deployment.
*/
ログイン後にコピー

Assignment Operators

let number = 100;

// Both statements add 10
number = number + 10;
number += 10;

console.log(number);
// => 120
ログイン後にコピー

String Interpolation

let age = 7;

// String concatenation
"Tommy is " + age + " years old.";

// String interpolation
`Tommy is ${age} years old.`;
ログイン後にコピー

Conditional Statements

const isMailSent = true;

if (isMailSent) {
  console.log("Mail sent to recipient");
}
ログイン後にコピー

Ternary Operator

var x = 1;

// => true
result = x == 1 ? true : false;
ログイン後にコピー

Logical Operators

true || false; // true
10 > 5 || 10 > 20; // true
false || false; // false
10 > 100 || 10 > 20; // false
ログイン後にコピー

Comparison Operators

1 > 3; // false
3 > 1; // true
250 >= 250; // true
1 === 1; // true
1 === 2; // false
1 === "1"; // false
ログイン後にコピー

Arrays

const fruits = ["apple", "orange", "banana"];

// Different data types
const data = [1, "chicken", false];
ログイン後にコピー

Objects

const apple = {
  color: "Green",
  price: { bulk: "$3/kg", smallQty: "$4/kg" },
};
console.log(apple.color); // => Green
console.log(apple.price.bulk); // => $3/kg
ログイン後にコピー

Classes

class Dog {
  constructor(name) {
    this._name = name;
  }

  introduce() {
    console.log("This is " + this._name + " !");
  }

  // Static method
  static bark() {
    console.log("Woof!");
  }
}

const myDog = new Dog("Buster");
myDog.introduce();

// Calling static method
Dog.bark();
ログイン後にコピー

Modules

// myMath.js

// Default export
export default function add(x, y) {
  return x + y;
}

// Named export
export function subtract(x, y) {
  return x - y;
}

// Multiple exports
function multiply(x, y) {
  return x * y;
}
function duplicate(x) {
  return x * 2;
}
export { multiply, duplicate };
ログイン後にコピー

Asynchronous Processing

function helloWorld() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve("Hello World!");
    }, 2000);
  });
}

async function msg() {
  const msg = await helloWorld();
  console.log("Message:", msg);
}

msg(); // Message: Hello World! <-- after 2 seconds
ログイン後にコピー

This quick reference guide covers a wide range of topics from the basics to more advanced JavaScript concepts. Be sure to download it here and make it a handy tool for your coding journey!

以上がJavaScript チートシートの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
関連するチュートリアル
人気のおすすめ
最新のコース
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート