![](https://i.imgur.com/56C2ubQ.png =200x) # Coaching - Back to Basics 2 with Founders and Coders --- ## Functions ---- ### What is a function? Some lines of code that do a predefined task. A function may take some input and return an output. ---- ### Why do we use functions? ---- #### Define reusable code Declare code which can be used in many places to do similar things with different inputs to give different outputs. ---- #### Modularise our code Break our code up into sections. ---- #### Help us understand our code - Having a well named function is easier to understand than a list of statements. - A meaningful name makes it easier to understand what the function does. A function that adds two numbers can be "addTwoNumbers". ---- #### Writing a function ---- ```javascript= function addTwoNumbers(num1,num2){ return num1+num2; } var total = addTwoNumbers(2,3) // total is assigned the returned value ``` ---
{"metaMigratedAt":"2023-06-15T23:42:31.313Z","metaMigratedFrom":"YAML","title":"Coaching - Back to Basics 2","breaks":true,"slideOptions":"{\"theme\":\"white\"}","contributors":"[{\"id\":\"2967aacf-1990-431e-b963-91e79ce4a2bf\",\"add\":1008,\"del\":0}]"}
    198 views
   Owned this note