Function calling orders in javascript

Viewed 30

I'm new to coding and I started with javascript. It's been a smooth journey for me but I have a question, why does I see people call function before define it first?

Example:

doSomething();

function doSomething(){
    console.log("Hello World");
}

Not like this?

function doSomething(){
    console.log("Hello World");
}

doSomething();

Thank you.

1 Answers
doSomething();

function doSomething(){
    console.log("Hello World");
}
function doSomething(){
    console.log("Hello World");
}

doSomething();

both are same . when the javascript debugger comes to this line doSomething() then he will go to find that function and if he will not able to find that then it will show an error .

another concept is

    function doSomething(){
        console.log("Hello World");
}

this total function will not compile until the compiler/javascript debugger find the decalared function that is doSomething() .

Related