JavaScript

Home|JavaScript

JavaScript Interview Prep Practice Problems Part 2

Part 1 function getTotal() { //convert object to an array var args = Array.prototype.slice.call(arguments); if (args.length === 2) { return args[0] + args[1]; } else if (args.length === 1) { return function(num2) { return args[0] + num2; }; } } console.log(getTotal(10, 20)); console.log(getTotal(5, 40)); console.log(getTotal(3)(30)); console.log(getTotal(8)(12)); Output: 30 45 33 20 Process finished

By |2021-03-06T03:42:00-04:00March 6th, 2021|JavaScript|0 Comments

JavaScript Interview Prep Practice Problems Part 1

Part 2 An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. (function doubleNumber(num) { return num * 2; })(10); (function () { function getTotal(a, b) { return a + b; } var $ = 'currency'; if (true) console.log('hello world'); })(); Create 5

By |2021-03-06T03:41:46-04:00March 3rd, 2021|JavaScript|0 Comments
Go to Top