跳到主要内容

JS/TS

Runtime

  • Deno
  • Node
  • V8
  • Bun
  • Cloud
    • Cloudflare Worker
    • Vercel Edge Runtime

Modules

RuntimeNameKeywork
Node.jsCommonJSrequire/exports/module.exports
Node.js/BrowserES Modulesimport/export default

Job Control

Sequence

Condition

Loop

for (var i=0;i<length;i++){
console.log(i);
}

const array = ["one", "two", "three"]
array.forEach(function (item, index) {
console.log(item, index);
});

let colors = ['red', 'green', 'blue'];
for (const color of colors){
console.log(color);
}

Browser

  • XMLHttpRequest

      var url = 'https://example.com';
    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;
    xhr.open('GET', url);
    xhr.setRequestHeader('Header','Value');
    xhr.send('Data');
  • fetch

      var url = 'https://example.com';
    fetch(url,{
    "method": "POST",
    "headers": {
    "accept": "-/-"
    },
    "body": "body data",
    "mode": "cors",
    "credentials": "include"
    })
  • fetch console.log headers

    fetch('https://example.com').then(response => { console.log(response.headers)]})
  • fetch console.log response

    fetch('https://example.com').then(response => response.text())
    .then(json => {
    console.log(json);
    })
  • cors checker

    fetch("https://example.com",{
    "method": "POST",
    "headers": {
    "accept": "-/-",
    "Access-Control-Allow-Origin": "example.com"
    },
    "body": "body data",
    "mode": "cors",
    "credentials": "include"
    })

NodeJS

TypeScript