diff --git a/lib/util.js b/lib/util.js index 37008b2d176062..85af547ebb81f7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -173,8 +173,12 @@ function inspect(obj, opts) { stylize: stylizeNoColor }; // legacy... - if (arguments[2] !== undefined) ctx.depth = arguments[2]; - if (arguments[3] !== undefined) ctx.colors = arguments[3]; + if (arguments.length >= 3 && arguments[2] !== undefined) { + ctx.depth = arguments[2]; + } + if (arguments.length >= 4 && arguments[3] !== undefined) { + ctx.colors = arguments[3]; + } if (typeof opts === 'boolean') { // legacy... ctx.showHidden = opts;