Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Functions

Friday, December 17, 2021

JavaScript Functions

A JavaScript function is a piece of code that is defined once and can be reused through your program.  A function can have arguments or parameters that you can pass into it and returns a value.  If an explicit return value is not specified the return value is "undefined".  During invocation of the function, the function returns the value of "this" keyword, which represents the context of the function.

As you can see a function is a lot like a method.  If a function is defined as a property of an object it is in fact called a method of the object.  It is import to keep in mind that functions in JavaScript are objects and they have the benefits of any objects, meaning they can be self contained, which provide them with a vast amount of flexibility.



The following code is a simple function that adds two numbers together


            
<script>
        function addNumbers(x, y) {
            return x + y;
        }

        console.log("The sum of 1 + 3 is " + addNumbers(1, 3));
</script>






The code above creates a function called addNumbers with two parameters and returns the sum of the two numbers


3 comments:


  1. It is shockingly simple to find 3 BHK pads and 2 BHK pads in Noida Extension and are accessible at reasonable rates.visit:- Ace Divino

    ReplyDelete
  2. It was nice to read your blog. If anyone needs any type of case study and assignment help at the cheapest price then visit our website:- My Case Study Help. We are the best Assignment Help Australia website, provide all types of services for MBA Assignment Help, Nursing Case Study Help, Law Case Study Help and Engineering students. Avail Assignment Writing Service with the world's most trusted and no1 company for Case Study and Assignment Help in Australia. Get professionally prepared assignment by our amazing Case Study Writers with 100% quality check and plagiarism free paper.

    ReplyDelete
  3. I appreciate you sharing this blog. It's a fantastic blog, and I'm extremely impressed by how valuable it is. Are you aware? How are dice rolled on a d4? If not, learn more about it by looking at the d4 dice online blog. This blog guide you more.

    ReplyDelete

Search This Blog