TIL is my collection of short, technical daily learnings. 254 and counting.
Writing Math.max in JavaScript
For a recent talk I examined some JavaScript implementations in Node, and ended up reading the source code for Math.max, which does this: Math.max(100, 1); // 100 Here’s the code: extern macro Float64Max(float64, float64): float64; transitioning javascript builtin MathMax( js-implicit context: NativeContext)(...arguments): Number { let result: float64 = MINUS_V8_INFINITY; const argCount = arguments.length; for (let i: intptr = 0; i < argCount; i++) { const doubleValue = TruncateTaggedToFloat64(arguments[i]); result = Float64Max(result, doubleValue); } return Convert<Number>(result); } To better understand this function, I decided to write my own implementation in JavaScript: ...