enemy reacting to player

I'm trying to make an enemy know when to dodge and/or block an attack from the player, and I'm not sure how to start, I suppose using ray/line cast to see if the player is in sight but beyond that not too sure. If someone could point me in the right direction on how to do that, that would be great. I'm working in javascript but pseudo code is great

You could check the distance from the player to all enemies (use FindGameObjectsWithTag and then a "for - in" to iterate through the enemies) on each gunshot and have the enemies react to the "sound." Or, you might want to :

if (gunshot){
   var enemiesList: GameObject[] = GameObject.FindGameObjectsWithTag("Enemy");
   for (var enemy: GameObject in enemiesList){
       if (enemy.renderer.isVisible){  // you might have to do a GetComponent to find the renderer, depending on your hierarchy
          // program your evasion routine here, or send a message to that enemy to evade.
       }
   }
}

This will make only the enemies in your camera (if you have only one camera... it will return "true" for every gameobject visible in ANY camera) react to the gunshots. This will simulate the enemies you are shooting at knowing that bullets are flying nearby... but the rest of the enemies will behave as normal (so you won't have enemies behind you running for cover).