JavaScript
31.9K subscribers
1.01K photos
9 videos
33 files
693 links
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
Download Telegram
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
๐Ÿ‘8โค2๐Ÿ”ฅ2๐Ÿคฃ2๐Ÿค”1
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
๐Ÿ‘10๐Ÿค”4โค2๐Ÿ”ฅ2๐Ÿคฉ1
๐Ÿซก Teable: Open Source Airtable Alternative atop Postgres

Airtable is a popular data table database SaaS, but hereโ€™s a NestJS-powered open-source alternative in a similar manner that sits atop Postgres. GitHub repo.

Teable Team
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘4โค2๐Ÿ”ฅ2๐Ÿคฃ1
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
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘4โค1๐Ÿ”ฅ1
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
๐Ÿ‘9๐Ÿ”ฅ5โค1
๐Ÿฅณ Next.js Global Hackathon

- 500 teams
- 10 days


Next.js team
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ”ฅ9๐Ÿ‘2
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
๐Ÿ‘3๐Ÿ”ฅ2โค1
๐Ÿ‘ 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
Please open Telegram to view this post
VIEW IN TELEGRAM
โค5๐Ÿ‘4๐Ÿ”ฅ2
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โค2๐Ÿ”ฅ1
โค14๐Ÿค”6๐Ÿ‘3
๐Ÿ‘€ 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
Please open Telegram to view this post
VIEW IN TELEGRAM
โค6๐Ÿ”ฅ2๐Ÿคฉ2๐Ÿ‘1
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โค1