Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to call a JavaScript Function from an onmouseover Event ?
Next article icon

How to Call a JavaScript Function from Chrome Console ?

Last Updated : 01 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

One can call a JavaScript Function from the Chrome Console. We will learn how can we call the function in the console that is written in JavaScript.

Steps to call a JavaScript Function from Chrome Console

Open the Chrome Console

You can open the Chrome Console by right-clicking on your webpage, selecting "Inspect" from the context menu, and then clicking on the "Console" tab. Alternatively, you can use the keyboard shortcut Ctrl+Shift+I in Windows or Cmd+Opt+I on Mac to open the Developer Tools and then click on the "Console" tab.

console
To Open the Console in the Chrome.

Call the Function

Once the console is open, you can call any JavaScript

function that is defined in the script(<script> </script>)tag in the HTML or in the JavaScript file by typing the function name followed by parentheses () and pressing Enter.

For example: If you have a function named myFunction, you would type myFunction() in the console and press Enter to execute it.

HTML
<!DOCTYPE html> <html lang="en">    <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width, initial-scale=1.0">     <title>Document</title> </head>    <body>     <h1></h1>     <script>         function myFunction(){             console.log(2+3);         }     </script> </body>    </html> 

Output:

output
Output of the Code in the Console

Other Types of function calls

By Passing Arguments:

If your function requires arguments, you can include them within the parentheses.

Example: To demonstrate calling myFunction(arg1, arg2) would call myFunction with arg1 and arg2 as arguments in console.

HTML
<!DOCTYPE html> <html lang="en">    <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width,                                    initial-scale=1.0">     <title>Document</title> </head>    <body>     <h1></h1>     <script>         function myFunction(x,y){             console.log(x+y);         }     </script> </body>    </html> 

Passing an x and y value as an arguments to the myFunction() in console as myFunction(6,7) gives an output of 13 in console;

Output:

Screenshot-2024-03-18-210232
Output of argument myFunction().

By using Return Value

After executing the function, the console will display the return value of the function. If the function does not return a value, you might see undefined printed in the console. This is normal behavior for functions that do not explicitly return a value.

Example: In the above output 13 is the return value because in the code there is an return value like console.log(), if there is no return value is gives the output has Undefined.

HTML
<!DOCTYPE html> <html lang="en">    <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width, initial-scale=1.0">     <title>Document</title> </head>    <body>     <h1></h1>     <script>         function myFunction(x,y){            //No return value         }     </script> </body>    </html> 

Output:

Screenshot-2024-03-18-211813
Output of the above code

Next Article
How to call a JavaScript Function from an onmouseover Event ?
author
suryateja9t06
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Questions

Similar Reads

  • Call a JavaScript Function from Chrome Console
    Google Chrome does not allow JavaScript to run from URLs due to security issues. The following are the steps and instructions to follow to Call a JavaScript Function from Chrome Console. Steps to call a JavaScript Function from Chrome ConsoleYou can follow the below steps to call and write a JavaScr
    2 min read
  • How to Call a JavaScript Function from an onsubmit Event ?
    The onsubmit event attribute in HTML is triggered when a form is submitted. It is also useful for validating form data or performing actions before any submission and ensures better control and validation of user inputs before data is sent. The below methods can be used to call a JavaScript function
    2 min read
  • How to Call a JavaScript Function from an onmouseout Event ?
    The onmouseout event in JavaScript triggers when the mouse pointer leaves an element. This event is commonly used in web development to execute certain functions when a user moves the mouse away from a specific area on the webpage. Below are the approaches to call a JavaScript function from an onmou
    3 min read
  • How to call a JavaScript Function from an onmouseover Event ?
    The onmouseover event in JavaScript is triggered when the mouse pointer moves onto an element, such as a button, image, or text. We will see how to call JavaScript function from an onmouseover event in various ways, like using the onmouseover Attribute and Using Event Listener. Table of Content Usin
    2 min read
  • How to call Typescript function from JavaScript ?
    In this article, we will try to understand all the facts which are associated with how we may call typescript function from JavaScript. TypeScript supports the existing JavaScript function syntax for declaring and calling it within the program or the code snippet. Let us quickly understand how we ma
    2 min read
  • How to create an Asynchronous function in Javascript?
    JavaScript is a single-threaded and synchronous language. The code is executed in order one at a time. But Javascript may appear to be asynchronous in some situations. Example: C/C++ Code <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" />
    6 min read
  • How to call JavaScript function in HTML ?
    In HTML, you can easily call JavaScript functions using event attributes like onclick and onload. Just reference the function name within these attributes to trigger it. You can also call functions directly within script blocks using standard JavaScript syntax. Let's create an HTML structure with so
    2 min read
  • How to Create a Custom Callback in JavaScript?
    A callback is a function that executes after another function has been completed in JavaScript. As an event-driven language, JavaScript does not pause for a function to finish before moving on to the next task. Callbacks enable the execution of a function only after the completion of another, making
    3 min read
  • How to find out the caller function in JavaScript?
    In this article, we see the methods to find out the caller function in Javascript. Sometimes, the developer may want to modify how a function works on the basis of its caller function. To find out the caller function name, we will use the Function object's caller property. Property: Function.caller
    1 min read
  • How does call stack handle function calls in JavaScript ?
    In this article, we will see how the call stack in JavaScript handles the functions in a JavaScript program. Call StackCall Stack in any programming language is a fundamental concept responsible for the execution of function calls made in the program. While execution it also manages their order of e
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences