Helaian Penipuan JavaScript

王林
Lepaskan: 2024-08-08 03:41:12
asal
1196 orang telah melayarinya

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!"));
Salin selepas log masuk

Numbers

let amount = 6;
let price = 4.99;
Salin selepas log masuk

Variables

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

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

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

Strings

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

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

Arithmetic Operators

5 + 5 = 10     // Addition
10 - 5 = 5     // Subtraction
5 * 10 = 50    // Multiplication
10 / 5 = 2     // Division
10 % 5 = 0     // Modulus
Salin selepas log masuk

Comments

// This is a comment

/*
You need to change this setting
before deployment.
*/
Salin selepas log masuk

Assignment Operators

let number = 100;

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

console.log(number);
// => 120
Salin selepas log masuk

String Interpolation

let age = 7;

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

// String interpolation
`Tommy is ${age} years old.`;
Salin selepas log masuk

Conditional Statements

const isMailSent = true;

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

Ternary Operator

var x = 1;

// => true
result = x == 1 ? true : false;
Salin selepas log masuk

Logical Operators

true || false; // true
10 > 5 || 10 > 20; // true
false || false; // false
10 > 100 || 10 > 20; // false
Salin selepas log masuk

Comparison Operators

1 > 3; // false
3 > 1; // true
250 >= 250; // true
1 === 1; // true
1 === 2; // false
1 === "1"; // false
Salin selepas log masuk

Arrays

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

// Different data types
const data = [1, "chicken", false];
Salin selepas log masuk

Objects

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

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();
Salin selepas log masuk

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 };
Salin selepas log masuk

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
Salin selepas log masuk

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!

Atas ialah kandungan terperinci Helaian Penipuan JavaScript. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

sumber:dev.to
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!