what is the difference between using drupal_add_js and ['#attached'] What is the difference between drupal_add_js() and $form['#attached']['js'][] ? 
When is the purpose of using each of the above functions?

(I mean I know that it is used to attached js to say form if used inside form but when is drupal_add_js used and when is $form['#attached']['js'][] used ?)
If you are using drupal_add_js() in your form building function, you are attaching JavaScript to a page, and that's it.

If you are using $form['#attached']['js'], other modules may interact, test and change it as they need, using hook_form_alter(). That's the way you should choose every time your JavaScript is functionally related to particular form.

Other than that, they are functionally the same.

Note that it is usually better to use JavaScript libraries than plain JavaScript files, as they allows you to declare versions, keep relations between JS and CSS, manage dependencies, well, they are generally way more powerful.

Of course then you should use $form['#attached']['library'] when your JavaScript Library is functionally related to particular form, and only use drupal_add_library() when no form is in any way related to library's function.