- If there is no specific custom namespace specified or variable is defined outside the function then variable is defined in global namespace. Its a global variable. But if variable is defined in any function then its local variable.
- The scope of Global variable is till the our page is loaded where script is added. As we move on another page scope of global variable ends. If we reload the page again all our global variables scope ends and created again.
- If we use variable without declaring those then these variables are global variables. That means if we use variable in function without declaring it, till variable is available outside the function. So its really important to declare the variables.
- Its best practice to use local variables unless and until we requires global variables. Or at least we must specify custom namespaces as explained in point 6.
- Its really very important to use proper namespace name as per the functionality whenever using the JSOM. It avoids collision of variables if two JSOM web parts are added on the same page and variable names are same.
- typeof operator is used to get the variable type asalert(typeof MyCustomNameSpace .cssFileURL);
Above line will return the ”string” type of MyCustomNameSpace .cssFileURL variable as
Figure 1 : Using typeof operator
typeof operator returns one of the following types
Enjoy Reading :)
As usual any comment / suggestions / feedback / questions always welcome :)