GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript-notes/12-functions-custom.md at master · geekysrm/javascript-notes

Expand file tree

/

12-functions-custom.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
45 lines (27 loc) · 1.1 KB
/

12-functions-custom.md

Copy path

File metadata and controls

45 lines (27 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

Functions - Custom

  • Functions are created/ defined then they are called.

  • Defining a function:

      // Function definition
      
      function calculateBill() {
      	// this is the function body
      	console.log('running calculateBill');
      }
  • Calling a function:

      // Function call or run
      
      calculateBill(); // running calculateBill (returns undefined)
  • Variables created inside a function are not available outside the function. e.g. total above.

    It is a temporary variable. After running of the function is complete, the variable is cleaned up or garbage-collected.

  • Returning value from function:

      function calculateBill() {
      	const total = 100 * 1.13;
      	return total; // total is returned
      }
      
      calculateBill(); // returns 112.999999999
  • Capturing returned value from a function into a variable:

    const myTotal = calculateBill(); (myTotal will have value 112.999999999)

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.