View the list of all variables in Google Chrome Console using JavaScript Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue 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: for (let variable in window) { if (window.hasOwnProperty(variable)) { console.log(variable); } } Example: <!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: let variables = Object.keys(window); console.log(variables); Example: <!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: Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now! Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 20 Sep, 2019 Like Article Save Article Previous D3.JS (Data Driven Documents) Next How to backup WordPress database ? Share your thoughts in the comments Add Your Comment Please Login to comment...