View the list of all variables in Google Chrome Console using JavaScript Last Updated : 20 Sep, 2019 Comments Improve Suggest changes Like Article Like Report All the variables in Google Chrome can be listed for the use of debugging. There are two approaches to list all variables: Method 1: Iterating through properties of the window object: The window object in JavaScript represents the current browser's window. The properties of this object can be used to find the variables of the Chrome browser. Each of the properties of the window object is first checked with the hasOwnProperty() method. This ensures that the object has the property as its own property. Syntax: javascript for (let variable in window) { if (window.hasOwnProperty(variable)) { console.log(variable); } } Example: html <!DOCTYPE html> <html> <head> <title> View the list of all variables in Google Chrome Console in JavaScript </title> </head> <body> <h1 style="color:green;"> GeeksforGeeks </h1> <b> View list of all JavaScript variables in Google Chrome Console </b> <p> Click on the button to view list of all JavaScript variables in the Google Chrome Console </p> <button onclick="findAllVariables()"> Click here </button> <script type="text/javascript"> function findAllVariables() { for (let variable in window) { if (window.hasOwnProperty(variable)) { console.log(variable); } } } </script> </body> </html> Output: Console Output: Method 2: Using the Object.keys() method: The Object.keys() method is used to return the properties of the given object as an array. As the window object represents the current browser's window, the properties of this object can be used to find the variables like the previous method. The Object.keys() method is passed the window object as the parameter to get its keys. Each of the keys in this object represents a variable of the Google Chrome browser. These can then be listed in the console. Syntax: javascript let variables = Object.keys(window); console.log(variables); Example: html <!DOCTYPE html> <html> <head> <title> View the list of all variables in Google Chrome Console in JavaScript </title> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <b> View list of all JavaScript variables in Google Chrome Console </b> <p> Click on the button to view list of all JavaScript variables in the Google Chrome Console </p> <button onclick="findAllVariables()"> Click here </button> <script type="text/javascript"> function findAllVariables() { let variables = Object.keys(window); console.log(variables); } </script> </body> </html> Output: Console Output: Create Quiz Comment S sayantanm19 Follow 0 Improve S sayantanm19 Follow 0 Improve Article Tags : JavaScript Web Technologies Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like