What is the reason for wrapping the entire content of a javascript source file in a function book?



What is the reason for wrapping the entire content of a javascript source file in a function book?..

Answer / Prashant Sirohi

Wrapping the entire JavaScript code in a function (usually called an Immediately Invoked Function Expression or IIFE) helps to avoid conflicts with other scripts, encloses variables and functions within their own scope, and can help to create anonymous functions for better security.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

What is the importance of <script> tag?

1 Answers  


How to comment javascript code?

1 Answers  


What is a null variable in javascript?

1 Answers  


Is null in javascript?

1 Answers  


Why is javascript not oop?

1 Answers  


Why is javascript dangerous?

1 Answers  


Hello , I am using following java script to open new window in I.E,but i am facing an issue the new window hangs often while opening,when you move mouse it opens normally.Can any body help me why this is happening as i am unable to understand this issue?please please if any one know so kindly help me I am in real difficulty through this issue.Thanks 'if(window.clipboardData){clipboardData.setData("Text","' + a.PatID + '");}' + 'ordwindow= window.open ("' + @OrderDetailURL + '", "RXOrderDetail", "location=0,status=0,menubar=0,toolba r=0,scrollbars=1,resizable=1"); ordwindow.moveTo(parent.screenLeft,0);var x; x=new ActiveXObject("WScript.Shell");x.SendKeys("% "); x.SendKeys ("x"); //fcttest((sp_RX_ChangeOrderStatus ' + '''' + a.DocID + '''' + ', 1, ' + convert(varchar,@SessionID) + '));' As [W],

1 Answers  


What is the role of a strict mode in javascript?

1 Answers  


What is the ‘Strict’ mode in JavaScript and how can it be enabled?

1 Answers  


Where do I put javascript code in html?

1 Answers  


What will be the output of the code below? var Y = 1; if (function F(){}) { y += Typeof F;</span> } console.log(y);

1 Answers  


why jsp

0 Answers  


Categories