0

I used a function with global and local variable below is my code:

var aNumber = 100;
tweak();

function tweak()
{
    // This prints "undefined", because aNumber is also defined locally below.
    document.write(aNumber);

    if (false)
    {
        var aNumber = 123; 
    }
}

What is the work of tweak(); I didn't understand. Anyone can help me please with details?

Fameless
  • 345
  • 3
  • 17
  • 6
    So what is your question? – nnnnnn Oct 14 '15 at 12:31
  • 1
    Pease give your question a title describing what it is about--which is what? –  Oct 14 '15 at 12:37
  • @pherris — You just edited the question to **add** a question which is answered by a comment in the code in the question already. – Quentin Oct 14 '15 at 12:39
  • @torazaburo the order is OK because the code is processed before executed. Check out hoisting: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting – pherris Oct 14 '15 at 12:40
  • @Quentin I intended to move the question from the comment up to the text above the code. The comments here show that people aren't seeing what the question actually is... – pherris Oct 14 '15 at 12:41
  • @pherris — Except the comment in the code isn't a question, it is an answer (to an unasked question). – Quentin Oct 14 '15 at 12:42
  • @Quentin, ah, will check out the other answer. thx. – pherris Oct 14 '15 at 12:44
  • Any of those answers are not expected – Fameless Oct 21 '15 at 11:10

0 Answers0