Where is JavaScript?


  • 0
    K
    var language = 'javascript';
    var waiting = function(lang){
        lang = lang || '';
        return 'Waiting for '+ lang;
    };
    
    waiting();

  • 0
    J

    What exactly are you trying to do?


  • 0
    K

    Want to see possibility to solve this task on JavaScript...


  • 0
    J
    var language = 'javascript';
    var waiting = function(lang){
        lang = lang || '';
        return 'Waiting for '+ lang;
    };
    
    waiting(language); //You didnt pass a variable to this function;
    //output: "Waiting for javascript"
    

    Is this what you wanted to to?

    when you call the function waiting , a new execution context is created which has its own lang variable which turned out to be undefined in you case and that is set to an empty string in the first line.

    Take another case :

    var lang = 'javascript';
    var waiting = function(){
        lang = lang || '';
        return 'Waiting for '+ lang;
    };
    waiting(); 
    //output: "Waiting for javascript"
    

    In this case lang is not found in the functions execution context so its looks up the previous context in the stack and finds a lang there and uses that


  • 0
    K

    Nope... That was kind of joke question....
    Real question was that I can NOT submit solution for this algorithm in JAVASCRIPT language.... =( (There are only java, go, c, c++ for this particular question)

    P.S
    In js language you can pass or you can not pass arguments in function call.... interpretator will pass it as valid code anyway.....


  • 0
    A

    Math.random() is 1 exclusive, you'll have a hard time passing the best I believe.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.