JavaScript-muotoilija
Siisti ja pienennä JavaScript
Sisennys:
Syöte
Tuloste
Muotoiltu JavaScript ilmestyy tähän...
Esimerkit
| Tyyppi | JavaScript | Käytä |
|---|---|---|
| Muotoile | function greet(name){if(!name){return "Hello!"}return "Hello, "+name+"!"} | |
| Muotoile | const users=[{id:1,name:"Ann"},{id:2,name:"Bob"}];const names=users.map(u=>u.name).filter(Boolean); | |
| Muotoile | class Queue{constructor(){this.items=[]}push(x){this.items.push(x);return this}pop(){return this.items.shift()}get size(){return this.items.length}} | |
| Muotoile | async function load(url){try{const res=await fetch(url);if(!res.ok)throw new Error(res.status);return await res.json()}catch(e){console.error(e);return null}} | |
| Pienennä | function add(a, b) { // sum two numbers return a + b; } | |
| Pienennä | export const TAX = 0.23; export function gross(net) { return net * (1 + TAX); } |