- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of ()(parenthesis) brackets in accessing a function in JavaScript?
The ()(parenthesis) brackets play an important role in accessing a function. Accessing a function without () will return the function definition instead of the function result. If the function is accessed with () then the result can be obtained.
Without ()
Example
In the following example, the function is accessed without () so the function definition is returned instead of the result as shown in the output.
<html> <body> <script> function toCelsius(f) { return (5/9) * (f-32); } document.write(toCelsius); </script> </body> </html>
Output
function toCelsius(f) { return (5/9) * (f-32); }
With ()
Example
In the following example, the function is accessed with () so instead of the function definition, the result is displayed as shown in the output.
<html> <body> <script> function toCelsius(f) { return (5/9) * (f-32); } document.write(toCelsius(208)); </script> </body> </html>
Output
97.77777777777779
Advertisements