Skip to content

Instantly share code, notes, and snippets.

View helderjbe's full-sized avatar
🎯
Focusing

HEsteves helderjbe

🎯
Focusing
View GitHub Profile
function sum() {
sum.a ??= 10;
sum.b ??= 20;
return sum.a + sum.b;
}
console.log(sum()); // 30
sum.a = 30;
function sum() {
let result = 0;
for (const argument of arguments) {
result += argument;
}
return result;
}
sum(5, 8); // 13
console.log(Math.ceil(0.5)); // 1
with (Math) {
console.log(ceil(0.5)); // 1
}
// Out of 'with (Math) {...}', it returns an error
console.log(ceil(0.5)); // Uncaught ReferenceError: ceil is not defined
let a = null;
a ??= 10;
console.log(a); // "10"
let b = "something";
b ??= 10;
console.log(b); // "something"
const x = null;
console.log(x ?? "Hey"); // "Hey"
const y = 10;
console.log(y ?? "Something"); // 10
const crypto = require("crypto");
const secret = "YOUR_SECRET_KEY" // Replace this with the key from static-auth-secret
function generateTurnKey() {
// The username is a timestamp that represents the expiration date of this credential
// In this case, it's valid for 12 hours (change the '12' to how many hours you want)
const username = (Date.now() / 1000 + 12 * 3600).toString();
// Now create the corresponding credential based on the secret
function App() {
const [varA, setVarA] = useState(0);
useEffect(() => {
if (varA > 0) return;
const timeout = setTimeout(() => setVarA(varA + 1), 1000);
return () => clearTimeout(timeout);
}, [varA]); // Great, we have our dependency array correctly set
function App() {
const [varA, setVarA] = useState(0);
useEffect(() => {
const timeout = setTimeout(() => setVarA(varA + 1), 1000);
return () => clearTimeout(timeout);
}, []); // Avoid this: varA is not in the dependency array!
return <span>Var A: {varA}</span>;
function App() {
const [varA, setVarA] = useState(0);
useEffect(() => {
if (varA >= 5) return;
const timeout = setTimeout(() => setVarA(varA + 1), 1000);
return () => clearTimeout(timeout);
}, [varA]);