
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript Function Call
The JavaScript call() function allows us to use the same method from different objects. The parameters are passed separately here.
Following is the code for the JavaScript function call() −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>JavaScript call()</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above buttons to check if adult or not </h3> <script> let sampleEle = document.querySelector(".sample"); let obj1 = { name: "Rohan", age: 22 }; function checkAdult(vehicle, country) { if (this.age > 18) { sampleEle.innerHTML =this.name + " you are an adult and can drive " + vehicle + " in " + country; } else sampleEle.innerHTML = this.name + " you are an adult and cannot drive " + vehicle + " in " + country; } document.querySelector(".Btn").addEventListener("click", () => { checkAdult.call(obj1, 'car','INDIA'); }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Articles
- How to call jQuery function with JavaScript function?
- Call a function with onclick() – JavaScript?
- How to call a Java function inside JavaScript Function?
- How to call a function in JavaScript?
- How to delay a JavaScript function call using JavaScript?
- JavaScript outsider function call and return the result
- How to call a JavaScript function on click?
- How to use setInterval function call in JavaScript?
- How to call a JavaScript function from C++?
- How to call a JavaScript function in HTML?
- How to call a function that returns another function in JavaScript?
- How to call a JavaScript function on submit form?
- How to call a JavaScript Function from Chrome Console?
- How do I call a JavaScript function on page load?
- How to call a JavaScript function from an onClick event?

Advertisements