
- 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 call() Method with Arguments.
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
The above code will produce the following output −
On clicking the “CLICK HERE” button −
- Related Articles
- Java Program to pass method call as arguments to another method
- What is a JavaScript call() Method?
- How to use jQuery.slice() method with no arguments?
- Call a function with onclick() – JavaScript?
- How to use typeof with arguments in JavaScript?
- Call a JavaScript class object with variable?
- How to call jQuery function with JavaScript function?
- Invoking functions with call() and apply() in JavaScript
- Parameters & Arguments in JavaScript.
- Named arguments in JavaScript.
- JavaScript Function Call
- How to use Spread Syntax with arguments in JavaScript functions?
- Can you have a method in Java with varying number of arguments?
- How to call a parent method from a child class in JavaScript?
- How to invoke a function with partials prepended arguments in JavaScript?

Advertisements