Giter Site home page Giter Site logo

jts272 / ci-advanced-js-arrow-functions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from code-institute-org/ci-advanced-js-arrow-functions

0.0 0.0 0.0 7 KB

CI | Advanced JavaScript > Arrow Functions > Using Arrow Functions | Template

JavaScript 100.00%

ci-advanced-js-arrow-functions's Introduction

Arrow Functions

To use this repository: - Click the "Use this template" button in the upper right - Choose a name for your repository and create it - In your own repository, click the green "Gitpod" button

Local fork created from this template for use in VS Code.

Quokka.js VS Code Extension used for real-time console output within the JS file.

node ${filename.js} used for actual terminal output.


ES6 arrow functions are usually defined as const:

  • Can't be overwritten or misused
  • Must be defined before being called

Steps to convert to conventional function to arrow function syntax:

  1. rename 'function' to 'const'
  2. put '=' between the name of the const and parentheses
  3. use the 'fat arrow' '=>' to point at the curly braces

Steps to convert this arrow function to a single-line function:

  1. remove the curly braces
  2. remove the 'return' statement
  3. put the expression on the same line after the '=>'

Think of the fat arrow as an 'implicit' return of what you want the function to return. Single line function only works for simple functions. Otherwise open the curly braces like usual.

Remember that as we are assigning these arrow functions to consts, each must be named differently. The 'function body' (as it were) of the arrow function can also be stylistically wrapped in parentheses.

Implicit return functions can optionally omit the parens when there is only one parameter.

If the function takes no params, empty parens '()' must still be used so JS knows you are declaring a function.

When returning multiple lines of code, the implicit return content should be wrapped in parens after the =>. The Prettier code formatter removes these parens, however.

ci-advanced-js-arrow-functions's People

Contributors

ckz8780 avatar jts272 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.