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/functions/declare.md at master · macik/javascript

Expand file tree

/

declare.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
40 lines (28 loc) · 702 Bytes
/

declare.md

Copy path

File metadata and controls

40 lines (28 loc) · 702 Bytes
Raw
Copy raw file
Download raw file
Edit and raw actions

Declaring Functions

Functions, like variables, must be declared. Let's declare a function double that accepts an argument called x and returns the double of x :

function double(x) {
    return 2 * x;
}

Functions are also values in JavaScript; they can be stored in variables (just like numbers, strings, etc ...) and given to other functions as arguments :

var double = function(x) {
    return 2 * x;
};

Declare a function named triple that takes an argument and returns its triple.

var triple = function(x) {
    return x * 3;
}
assert(triple);
assert(triple(4) === 12);
assert(triple(10) === 30);

You are visitor 01402792 — 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.