Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
// Type Assertion Functions demo (runtime-friendly) function assertIsString(value) { if (typeof value !== 'string') { throw new Error('Value is not a string'); } } function assert(condition, message) { if (!condition) { throw new Error(message); } } // Usage try { const input = 'hello'; assertIsString(input); console.log(input.toUpperCase()); // HELLO } catch (e) { console.log('string error:', e.message); } try { const x = 21; assert(typeof x === 'number', 'Value must be a number'); console.log(x * 2); // 42 } catch (e) { console.log('number error:', e.message); }
HELLO 42