mdn/js/1_javascript_building_blocks/2_functions

2_functions

dz / mdn / js / 1_javascript_building_blocks / 2_functions

Summary

Functions: Re-usable blocks of code

Node Tree

Nodes

functions
content functions
children built_in, custom, scope, functions_vs_methods, invoke, parameters, anonymous_funcs

built_in
content built-in
parents functions

invoke
content invoke: run or execute a function
parents functions

functions_vs_methods
content Functions vs Methods
parents functions

custom
content Custom
parents functions

parameters
content Parameters
children default, optional
parents functions

optional
content Optional
parents parameters

default
content Default
children default_ex (example)
parents parameters

default_ex
content hello(foo="bar")
parents default

anonymous_funcs
content Anonymous Functions
children arrow_funcs
parents functions

arrow_funcs
content Arrow Functions
children arrow_notation_ex (notation example), one_line_return_omit_braces_return, one_param_omit_parens
parents anonymous_funcs

one_param_omit_parens
content Can omit parentheses if there is only one parameter
parents arrow_funcs

arrow_notation_ex
content instead of function(event), write (event) =>
parents arrow_funcs

one_line_return_omit_braces_return
content If only one line that's a return statement, can omit braces and return keyword
parents arrow_funcs

scope
content scope
children function_scope, global
parents functions

global
content global
parents scope

function_scope
content Function Scope
parents scope