See below for JavaScript output: