← All examples

Parse a number

TypeScript Exceptions

try / catch

Flowchart (ISO 5807)

StartInput sReturn parseInt(s)EndFigure 1 — parse

Source code

function parse(s: string): number {
    try {
        return parseInt(s);
    } catch (e) {
        return -1;
    }
}