Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/tsc/dts/lib.deno.ns.d.ts>Deno.inspect

A modern runtime for JavaScript and TypeScript.
Latest
function Deno.inspect
import { Deno } from "https://deno.land/x/deno@v2.0.4/cli/tsc/dts/lib.deno.ns.d.ts";
const { inspect } = Deno;

Converts the input into a string that has the same format as printed by console.log().

const obj = {
  a: 10,
  b: "hello",
};
const objAsString = Deno.inspect(obj); // { a: 10, b: "hello" }
console.log(obj);  // prints same value as objAsString, e.g. { a: 10, b: "hello" }

A custom inspect functions can be registered on objects, via the symbol Symbol.for("Deno.customInspect"), to control and customize the output of inspect() or when using console logging:

class A {
  x = 10;
  y = "hello";
  [Symbol.for("Deno.customInspect")]() {
    return `x=${this.x}, y=${this.y}`;
  }
}

const inStringFormat = Deno.inspect(new A()); // "x=10, y=hello"
console.log(inStringFormat);  // prints "x=10, y=hello"

A depth can be specified by using the depth option:

Deno.inspect({a: {b: {c: {d: 'hello'}}}}, {depth: 2}); // { a: { b: [Object] } }

Parameters

value: unknown
optional
options: InspectOptions

Returns

string