Is there a way to check user permissions in javascript?
It is not secure to only rely on Javacript. It is better to separate that .js function which needs permission to execute from other codes then put in a file and load that .js file from your hook_preprocess_page if the user has permission (or some role). I implement this idea with user roles, you may use another strategy for checking the permission.

function THEME_preprocess_page(&amp;$var){
      global $user;
      if(in_array("SOME_ROLE_NAME_WITH_ACCESS_TO_JS_FUNCTION",$user-&gt;roles)) 
            drupal_add_js(drupal_get_path('theme', 'mytheme') .'/js/Your_js.js');

}


in your theme directory, I supposed you placed your .js files in /js directory. So you should create Your_js.js file in that directory and put that function inside it. If the user has appropriate role, that file with that function in it will be loaded and you can use it later, otherwise it won't.