Yes and no. It is possible when your facebook application is not shown in a tab because in a tab facebook runs no javascript and no user information is passed until the user clicked somewhere.
If you are writing a "real" facebook app, you could try the following code, I do this in PHP like this:
// Get user id
public function getUserId()
{
$user_id = 0;
try
{
$user_id = $this->facebook->api_client->users_getLoggedInUser();
}
catch(Exception $e)
{
$user_id = 0;
}
return $user_id;
}
If this code returns "0", a guest is viewing the application.