JavaScript Equivalent of var_dump() in PHP
Today’s article will discuss the JavaScript equivalent of var_dump()
in PHP.
JavaScript Equivalent of var_dump()
in PHP
The PHP var_dump()
function displays structured information about one or more expressions, including type and value. Arrays and objects are recursively scanned with indented values to show structure.
Most browsers provide debugging consoles. JavaScript provides a console object through which you can access the browser’s debug console.
Each browser works differently; depending on the browser, its specifics vary, but several features are typically provided.
To find more information about the console, click here.
Some of the console methods are:
console.log()
: For basic output of log information.console.debug()
: Sends a message to the browser’s console. It contains the log-level debug.console.assert()
: Logs a message and stacks the trace on the console if the first argument is false.console.count()
: Records the number of times this line has been called with the tag.console.dir()
: Displays an interactive list of properties of a specific JavaScript object. This list allows you to use expanded triangles to browse the contents of child objects.console.clear()
: Clears the console.console.error()
: Sends a message to the browser’s console. It contains an error message.
From any global object, the console object can be accessed. Browse the Window and WorkerGlobalScope scopes as worker-specific variants from the Properties console.
It is exposed as Window.console
and can be referred to as a console.
For example,
console.log('Hello World!')
The console.log()
method sends a message to the web console.
The message can be a single string (with optional replacement values) or one or more JavaScript objects. Depending on the use case, you can use any of the methods.
Let’s look at the example below. We have defined an object with key and value properties.
When you print this object, it will show what is inside the object.
Example:
const object = {
key: 'Message',
value: 'Hello, world!'
} console.log(object)
Output:
{
key: "Message",
value: "Hello, world!"
}
You may also access the complete code in this example here.
Shraddha is a JavaScript nerd that utilises it for everything from experimenting to assisting individuals and businesses with day-to-day operations and business growth. She is a writer, chef, and computer programmer. As a senior MEAN/MERN stack developer and project manager with more than 4 years of experience in this sector, she now handles multiple projects. She has been producing technical writing for at least a year and a half. She enjoys coming up with fresh, innovative ideas.
LinkedIn