Embed Javascript code to registered users only

WordPress provides the Conditional Tags. I think is_user_logged_in() tag will work for you. List of conditional tags available.


if ( is_user_logged_in()  ) 
{
  // include the JavaScript File
}

UPDATE: Also if you want to check the user roles etc.. you can use the current_user_can() you can check both the both roles and capabilities.
Better to use the wp_get_current_user(); function like :


$current_user = wp_get_current_user();

$roles = array('editor', 'author');

if( array_intersect($roles, $current_user->roles ) && is_user_logged_in() ) {

   // include javascript file here etc...

}