0
0

JavaScript速查表の宣伝記事 cheat sheets

Last updated at Posted at 2024-07-16

javascript-preview.png

こんにちは、皆さん!JavaScriptを学んでいる初心者の方々に朗報です!JavaScriptの速查表が登場しました!これで、重要な概念や関数、メソッドなどをすぐに確認できます。速查表の詳細はこちらからチェックしてください。

速查表の内容

コンソール

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

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

// エラーメッセージを標準エラーに出力
console.error(new Error("Oops!"));

数値

let amount = 6;
let price = 4.99;

変数

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

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

var a;
console.log(a); // => undefined

文字列

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

// => 21
console.log(single.length);

算術演算子

5 + 5 = 10     // 加算
10 - 5 = 5     // 減算
5 * 10 = 50    // 乗算
10 / 5 = 2     // 除算
10 % 5 = 0     // 剰余

コメント

// これはコメントです

/*
デプロイ前にこの設定を
変更する必要があります。
*/

代入演算子

let number = 100;

// どちらの文も10を加算します
number = number + 10;
number += 10;

console.log(number);
// => 120

文字列補間

let age = 7;

// 文字列連結
"Tommy is " + age + " years old.";

// 文字列補間
`Tommy is ${age} years old.`;

条件文

const isMailSent = true;

if (isMailSent) {
  console.log("Mail sent to recipient");
}

三項演算子

var x = 1;

// => true
result = x == 1 ? true : false;

論理演算子

true || false; // true
10 > 5 || 10 > 20; // true
false || false; // false
10 > 100 || 10 > 20; // false

比較演算子

1 > 3; // false
3 > 1; // true
250 >= 250; // true
1 === 1; // true
1 === 2; // false
1 === "1"; // false

配列

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

// 異なるデータ型
const data = [1, "chicken", false];

オブジェクト

const apple = {
  color: "Green",
  price: { bulk: "$3/kg", smallQty: "$4/kg" },
};
console.log(apple.color); // => Green
console.log(apple.price.bulk); // => $3/kg

クラス

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

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

  // 静的メソッド
  static bark() {
    console.log("Woof!");
  }
}

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

// 静的メソッドの呼び出し
Dog.bark();

モジュール

// myMath.js

// デフォルトエクスポート
export default function add(x, y) {
  return x + y;
}

// 通常のエクスポート
export function subtract(x, y) {
  return x - y;
}

// 複数のエクスポート
function multiply(x, y) {
  return x * y;
}
function duplicate(x) {
  return x * 2;
}
export { multiply, duplicate };

非同期処理

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! <-- 2秒後

この速查表は、JavaScriptの基本から応用まで幅広くカバーしています。ぜひ、こちらからダウンロードして、日々のコーディングに役立ててください!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0