Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » JavaScript

JavaScript | Some of the examples of user-defined functions



User-defined functions examples in JavaScript: Here, we are writing some of the examples of User-defined functions in JavaScript.
Submitted by Pankaj Singh, on October 10, 2018

1) Design a function, print message and assign the function to a variable and print it like a function

<html lang="en">
<head>
    <script>
        function hello(){
            document.write("Hello <Br />")
        }

        hello();
        a=hello;
        a();
    </script>
</head>
<body>
    
</body>
</html>

Output

Hello 
Hello 

2) Call a function and then define it

<html lang="en">
<head>
    <script>
        hello();
        function hello(){
            document.write("Hello <Br />")
        }
    </script>
</head>
<body>
    
</body>
</html>

Output

Hello

3) Define a function and call it in the body section

<html lang="en">
<head>
    <script>
        function hello(){
            document.write("Hello <Br />")
        }
    </script>
</head>
<body>
    <script>
        hello();
    </script>
</body>
</html>

Output

Hello

4) Call a function in head section and define it in the body section

<html lang="en">
<head>
    <script>
        hello(); 
    </script>
</head>
<body>
    <script>
        function hello(){
            document.write("Hello <Br />")
        }
    </script>
</body>
</html>

Output

None: Function will not call

5) Call a function and define it in the body section

<html lang="en">
<head>
    <script>
         
    </script>
</head>
<body>
    <script>
        hello();
        function hello(){
            document.write("Hello <Br />")
        }
    </script>
</body>
</html>

Output

Hello





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.