• Search form is empty!

  • 012 TypeScript - simple functions

    http://robertdunaway.github.io

    TypeScript code kata list

    All code kata lists

    Smiley face

    012 TypeScript - simple functions

    Duration

    10 minutes

    Brief

    Create simple, anonymous, and arrow functions.

    For more information

    BING/GOOGLE: “TypeScript functions”

    Instructions

    Get tutorial folder or the entire katas-typescript repo.
    Open the [before/*.sln] file and execute the kata.
    Feel free to execute this kata multiple times because repetition creates motor memory.

    Github

    Kata

    Create a simple function that adds two numbers.


    
        // Create a simple 'add' function.
        function add(a: number, b: number): number {
            return a + b;
        }
        console.log('named function');
        console.log('5 + 2 = ' + add(5, 2));
    
    


    Create an anonymous function that adds two numbers.


    
        // Create an ananymous 'add' function.
        var add2 = function (a: number, b: number): number {
            return a + b;
        }
        console.log('anonymous function');
        console.log('5 + 5 = ' + add2(5, 5));
    
    


    Create an arrow function that adds two numbers.


    
        // Create a function using the arrow function.
        var add3 = (a: number, b: number): number => {
            return a + b;
        }
        console.log('arrow function');
        console.log('10 + 5 = ' + add3(10, 5));
    
    

    Next

    Take a few minutes and imagine more examples.

    Smiley face

    0 comments:

    Post a Comment