In the above example, a function called logsHello is declared. The other two variations have their own uses and behaviors and are covered in later lessons. There are three ways to build a function. They also have their own scope, so variables assigned within a function are not available outside of the function – although they can make use of global variables. 😉įunctions adhere to a school of thought in programming called DRY, or Don’t Repeat Yourself. I like sorting items and placing the ones that are alike together, so this tip is right up my alley. They can also optionally return a value back.Īlthough they’re generally used to define code that can be called multiple times (to reduce having to rewrite that same code repeatedly), book 1 of You Don’t Know JS offers another tip: they can also be used to organize related bits of code into named collections. They can optionally take arguments (parameters), which are values that are passed to the function to be processed.
Learn why we use JavaScript Functions and be able to write correct function syntaxĪ function is a named section of code that can be called and reused. This material is basically ground-floor information that students need to know before they start the full course. I’m going to summarize what the pre-course covers for each of them.
There are nine units in Lambda School’s Full Stack Web Development Pre-course.