TGViewer
Channel Public Channel
JavaScript

JavaScript

@javascript

A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript ๐Ÿš€ Don't miss our Quizzes!

Let's chat: @nairihar
Subscribers
31K
Photos
1.2K
Videos
10
Links
899

Showing posts older than #2213 ยท Back to latest

Older Posts 20 shown
Post #2212 4.95K
CHALLENGE

function getCity(person) {
return person?.address?.city ?? 'Unknown';
}

const data = [
null,
{ name: 'Alice' },
{ name: 'Bob', address: null },
{ name: 'Charlie', address: { street: '123 Main' } },
{ name: 'David', address: { city: 'Boston' } }
];

const cities = data.map(getCity);
console.log(cities);
  • ๐Ÿ‘ 3
  • โค 2
Post #2211 5.25K
๐Ÿ‘€ Exploring Art with TypeScript, Jupyter, Polars, and Observable Plot

One of Denoโ€™s compelling features is its support for Jupyter Notebooks and easy notebook-style programming, such as is common in the Python world. Trevor looks at a practical use of using such a notebook environment for data exploration.

Trevor Manz
  • โค 6
  • ๐Ÿ”ฅ 2
  • ๐Ÿคฉ 2
  • ๐Ÿ‘ 1
Post #2210 4.98K
  • โค 14
  • ๐Ÿค” 6
  • ๐Ÿ‘ 3
Post #2209 5.2K
CHALLENGE

async function test() {
console.log('1');

setTimeout(() => {
console.log('2');
}, 0);

await Promise.resolve();
console.log('3');

new Promise(resolve => {
console.log('4');
resolve();
}).then(() => {
console.log('5');
});

console.log('6');
}

test();
console.log('7');
  • ๐Ÿ‘ 5
  • โค 3
  • ๐Ÿ”ฅ 1
Post #2208 4.98K
๐Ÿ‘ Bare: A New Lightweight Runtime for Modular JS Apps

Imagine something like Node.js but really stripped back: bare, if you will. Like Node, itโ€™s built on top of V8 and libuv (though it's designed to support multiple JavaScript engines) but Bareโ€™s approach is to provide as little as possible (a module system, addon system, and thread support) and then rely upon userland modules that can evolve independently of Bare itself. Itโ€™s an interesting idea โ€“ more details here.

Holepunch
  • โค 5
  • ๐Ÿ‘ 4
  • ๐Ÿ”ฅ 2
Post #2207 4.98K
  • ๐Ÿ‘ 3
  • ๐Ÿ”ฅ 2
  • โค 1
Post #2206 5.18K
CHALLENGE

const secretData = { password: 'abc123' };
const mySet = new WeakSet();
mySet.add(secretData);

// Later in the code
delete secretData.password;

const checkAccess = (obj) => {
console.log(mySet.has(obj));
};

checkAccess(secretData);
checkAccess({ password: 'abc123' });
  • โค 7
  • ๐Ÿ‘ 2
  • ๐Ÿ”ฅ 2
Post #2204 5.55K
  • ๐Ÿ‘ 9
  • ๐Ÿ”ฅ 5
  • โค 1
Post #2203 5.31K
CHALLENGE

let obj1 = { id: 1 };
let obj2 = { id: 2 };
let obj3 = { id: 3 };

const weakSet = new WeakSet([obj1, obj2]);

weakSet.add(obj3);
weakSet.delete(obj1);

obj2 = null;

const remainingObjects = [...weakSet];

console.log(remainingObjects);
  • ๐Ÿ‘ 2
  • ๐Ÿ”ฅ 1
Post #2201 5.33K
  • ๐Ÿ”ฅ 5
  • ๐Ÿ‘ 2
  • โค 1
Post #2200 5.24K
CHALLENGE

function Device(name) {
this.name = name;
this.isOn = false;
}

Device.prototype.turnOn = function() {
this.isOn = true;
return `${this.name} is now on`;
};

function Smartphone(name, model) {
Device.call(this, name);
this.model = model;
}

Smartphone.prototype = Object.create(Device.prototype);
Smartphone.prototype.constructor = Smartphone;

Smartphone.prototype.turnOn = function() {
const result = Device.prototype.turnOn.call(this);
return `${result} (model: ${this.model})`;
};

const myPhone = new Smartphone('iPhone', '13 Pro');
console.log(myPhone.turnOn());
  • ๐Ÿ”ฅ 7
  • โค 2
  • ๐Ÿ‘ 2
  • ๐Ÿคฃ 1
Post #2198 5.16K
  • ๐Ÿ‘ 10
  • ๐Ÿค” 4
  • โค 2
  • ๐Ÿ”ฅ 2
  • ๐Ÿคฉ 1
Post #2197 5.05K
CHALLENGE

class ShoppingCart {
constructor() {
if (ShoppingCart.instance) {
return ShoppingCart.instance;
}

this.items = [];
ShoppingCart.instance = this;
}

addItem(item) {
this.items.push(item);
}

getItems() {
return [...this.items];
}
}

const cart1 = new ShoppingCart();
const cart2 = new ShoppingCart();

cart1.addItem('Book');
cart2.addItem('Laptop');

console.log(cart1.getItems());
  • ๐Ÿ‘ 6
Post #2195 5.29K
  • ๐Ÿ‘ 7
  • ๐Ÿ”ฅ 5
  • โค 4
Post #2194 4.9K
CHALLENGE

function processInput(userInput) {
const defaultValue = 'default';
const value1 = userInput?.value ?? defaultValue;
const value2 = userInput?.value || defaultValue;

const result = {
a: 0 ?? 'zero',
b: '' ?? 'empty',
c: null ?? 'null',
d: undefined ?? 'undefined',
comparison: value1 === value2
};

console.log(result);
}

processInput({ value: '' });
  • ๐Ÿ‘ 7
Post #2193 5.16K
  • ๐Ÿ‘ 16
  • โค 5
  • ๐Ÿ”ฅ 2
Older posts โ†’
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’