Skip to content

Instantly share code, notes, and snippets.

View BiosBoy's full-sized avatar
⛰️
The bigger you know - the less you scared of.

Sviat Kuzhelev BiosBoy

⛰️
The bigger you know - the less you scared of.
View GitHub Profile
# Code Examples from "Top 5 Underestimated Native Browser Features You Should Be Using"
## 1. Bluetooth: Connecting to Devices Wirelessly 📡
### Example: Connecting to a Bluetooth Device
```typescript
async function connectToBluetooth() {
try {
function Person(name) {
this.name = name;
}
Person.prototype.greet = function() {
console.log(`Hello, my name is ${this.name}`);
};
const alice = new Person('Alice');
const userRole = 'admin';
if (userRole === 'admin' || userRole === 'editor' || userRole === 'moderator') {
console.log('Access granted');
} else {
console.log('Access denied');
}
const userRole = 'admin';
# Webpack Bundle Analyzer Examples
## Install the Package
```bash
npm install --save-dev webpack-bundle-analyzer
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const arr1 = [1, 2, 3, 4];
const result1 = arr1.flatMap(x => [x, x * 2]);
console.log(result1); // [1, 2, 2, 4, 3, 6, 4, 8]
const arr2 = ['a', 'b', 'c', 'd'];
console.log(arr2.at(-1)); // 'd'
console.log(arr2.at(-2)); // 'c'
const arr3 = [1, 2, 3, 4, 5];
const result2 = arr3.findLast(x => x % 2 === 0);
const originalArray = [1, 2, 3, 4, 5];
const slicedArray = originalArray.slice(2, 4);
console.log(slicedArray); // [3, 4]
console.log(originalArray); // [1, 2, 3, 4, 5]
const originalArray = [1, 2, 3, 4, 5];
const splicedArray = originalArray.splice(2, 2);
function* simpleGenerator() {
console.log("First execution");
yield 1;
console.log("Second execution");
yield 2;
console.log("Third execution");
}
const gen = simpleGenerator();
interface User {
name: string;
age: number;
isAdmin: boolean;
}
interface Employee extends User {
employeeId: number;
}
const maxUsers = 100;
const apiUrl = 'https://api.example.com/users';
// You know these won't change. They're constant.
let userCount = 0;
if (users.length > 0) {
userCount = users.length;
}
// Did we really need to use `let` here?
interface User {
id: number;
name: string;
email: string;
}
function updateUser(userId: number, updates: Partial<User>) {
// Imagine this function updates a user in the database
console.log(userId, updates);
}