Question: I have created a custom newform.aspx by cloning the form generated by SharePoint Designer and added it to a VS2010 project. Everything seems to be working fine like setting the value etc... but I couldn't figure out how to set the `Required` property of a field.

Based on a certain condition I would like to set the required property of a field to true or false.

I am accessing the controls using `CompositeField` and `BaseFieldControl` but they dont seem to give a handle to set required property value.

Any pointers are greatly appreciated.

Answer: 
This 

```
(function(){
  alert('hello');
})();

```

although it is a function is it called automatically so you dont/can't call it manually 

These can be useful for `for` loops like so

This will fail because i would be equal to 9 after 5 seconds

```
for(var i = 0; i < 10; i++) {
   window.setTimeout(function(){
      console.log(i);
   }, 5000)
}

```

So you could do this 

```
for(var i = 0; i < 10; i++) {
   (function(a){
      window.setTimeout(function(){
         console.log(a);
      }, 5000)
   })(i);
}

```

Also good for creating a "private" scope like this 

```
(function(){
   var test = 'hello';
   console.log( test ); // 'hello'
}());

   console.log( test ); // 'undefined'

```
It runs the function you just created. The reason to do this is that it encloses all of the code you write within a new scope. This means when you define `vars` and `functions`, they will be kept within the scope of that `function()` you just created.

In short, it encapsulates code.