JavaScript Hoisting - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
JavaScript Hoisting

JavaScript Hoisting

JavaScript Hoisting

Hoisting 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 Example

Here, we will use the variable and function before declaring them.

JavaScript Variable Hoisting

Let's see the simple example of variable hoisting.
  1. <script>  
  2. x=10;  
  3. document.write(x);  
  4. var x;  
  5. </script>  

JavaScript Function Hoisting

Let's see the simple example of variable hoisting.

  1. <script>  
  2. document.write(sum(10,20));  
  3. function sum(a,b)  
  4. {  
  5. return a+b;  
  6. }  
  7. </script>  

About Mariano

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.