What is difference between var x =1; and x=1;?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Oct 07, 2018

 

    2 Answers Written

  •  Sharad Jaiswal
    Answered by Morgan Garcia

    x=1 has no Variable declared to it

  •  Sharad Jaiswal
    Answered by Raj Kumar

    var x =1;
    When a variable declared with keyword 'var' its scope is functional scope.

    x=1;

    when a variable is declared like above then its scope is global. This variable is available to user as 'window.x' . That means it is available in global object of javascript

Please Login or Register to leave a response.

Related Questions

Advanced and Basic JavaScript Interview Questions

Explain what is Javascript? List some data types supported by Javascript?

Javascript Javascript is an object-oriented computer programming language commonly used to create interactive effects wi..

Ask a Question