This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(name) { | |
this.name = name; | |
} | |
Person.prototype.greet = function() { | |
console.log(`Hello, my name is ${this.name}`); | |
}; | |
const alice = new Person('Alice'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const userRole = 'admin'; | |
if (userRole === 'admin' || userRole === 'editor' || userRole === 'moderator') { | |
console.log('Access granted'); | |
} else { | |
console.log('Access denied'); | |
} | |
const userRole = 'admin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Webpack Bundle Analyzer Examples | |
## Install the Package | |
```bash | |
npm install --save-dev webpack-bundle-analyzer | |
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* simpleGenerator() { | |
console.log("First execution"); | |
yield 1; | |
console.log("Second execution"); | |
yield 2; | |
console.log("Third execution"); | |
} | |
const gen = simpleGenerator(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface User { | |
name: string; | |
age: number; | |
isAdmin: boolean; | |
} | |
interface Employee extends User { | |
employeeId: number; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
NewerOlder