C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript HoistingHoisting is a mechanism in JavaScript that moves the declaration of variables and functions at the top. So, in JavaScript we can use variables and functions before declaring them. JavaScript hoisting is applicable only for declaration not initialization. It is required to initialize the variables and functions before using their values. JavaScript Hoisting ExampleHere, we will use the variable and function before declaring them. JavaScript Variable HoistingLet's see the simple example of variable hoisting. <script> x=10; document.write(x); var x; </script> JavaScript Function HoistingLet's see the simple example of variable hoisting. <script> document.write(sum(10,20)); function sum(a,b) { return a+b; } </script>
Next TopicJavaScript Strict Mode
|