This file contains hidden or 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
| // Old way | |
| if (user && user.address && user.address.city) { | |
| console.log(user.address.city); | |
| } | |
| // Modern way with Optional Chaining | |
| console.log(user?.address?.city); | |
| // Nullish Coalescing | |
| const userName = user.name ?? 'Guest'; |
This file contains hidden or 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
| enum Direction { | |
| North, | |
| East, | |
| South, | |
| West | |
| } | |
| let myDirection: Direction = Direction.North; | |
| console.log(myDirection); // Output: 0 |
This file contains hidden or 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
| <div className="flex flex-col items-center p-6 bg-white shadow-md rounded-lg"> | |
| <h2 className="text-2xl font-bold mb-2">Card Title</h2> | |
| <p className="text-gray-700">This is a card description.</p> | |
| </div> | |
| import styles from './Card.module.scss'; | |
| <div className={styles.card}> | |
| <h2 className={styles.title}>Card Title</h2> |
This file contains hidden or 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
| class Singleton { | |
| constructor() { | |
| if (Singleton.instance) { | |
| return Singleton.instance; | |
| } | |
| this.data = []; | |
| Singleton.instance = this; | |
| } | |
| getData() { |
This file contains hidden or 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 record = #{ name: "Alice", age: 30 }; | |
| const tuple = #[1, 2, 3]; | |
| console.log(record.name); // Alice | |
| console.log(tuple[0]); // 1 | |
| const data = { type: 'user', info: { name: 'Alice', age: 30 } }; | |
| const result = match (data) { |
This file contains hidden or 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
| <script async src="analytics.js"></script> | |
| <script defer src="main.js"></script> | |
| <!-- Correct usage --> | |
| <script async src="https://example.com/ads.js"></script> | |
| <script defer src="app.js"></script> | |
| <script type="module" src="main.js"></script> |
This file contains hidden or 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 map = new Map(); | |
| map.set(1, 'Number one'); | |
| map.set('1', 'String one'); | |
| map.set(true, 'Boolean true'); | |
| console.log(map.get(1)); // Output: Number one | |
| const map = new Map(); | |
| map.set('a', 1); | |
| map.set('b', 2); |
This file contains hidden or 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
| "scripts": { | |
| "start": "node nightly --experimental-strip-types index.ts" | |
| } |
This file contains hidden or 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
| npm install apollo-server-express graphql | |
| const express = require('express'); | |
| const { ApolloServer, gql } = require('apollo-server-express'); | |
| // Define your type definitions (schema) | |
| const typeDefs = gql` | |
| type Query { | |
| hello: String | |
| } |
This file contains hidden or 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 input1 = [1, 2, 5, 3, 4, 7, 8, 6]; | |
| const input2 = [2, 5, 1, 3, 4]; | |
| const chaos = (arr) => { | |
| let operationCount = 0; | |
| let isChaos = false; | |
| arr.forEach((_, idx) => { | |
| const nextReversedIdx = arr.length - idx; | |
| const currentReversedIndex = nextReversedIdx - 1; |