Avatar for vprunet

vprunet

Member since Sep 2016 • Last active Feb 2017
  • 1 conversations
  • 1 comments

Most recent activity

    • 3 comments
    • 1,805 views
  • in JavaScript
    Avatar for vprunet

    Return within switch statements are handled like a break (and do not return anything).
    See the following example, with execution trace on Espruino and on node.js .

    function foo( arg ) {
        switch (arg) {
        case 'bar': console.log( 'is bar' ); return( 'bar' );
        case 'gee': console.log( 'is gee' ); break;
        default: console.log( 'is default' ); return( 'default' );
        };
        return( 'end' );
    }
    
    console.log( '<--', foo( 'bar' ));
    console.log( '<--', foo( 'gee' ));
    console.log( '<--', foo( 'foo' ));
    
    

    on espruino, shows as

    is bar
    <-- end
    is gee
    <-- end
    is default
    <-- end
    

    on node.js, shows as

    is bar
    <-- bar
    is gee
    <-- end
    is default
    <-- default
    
Actions