Make a particle effect on enemy death

Hi i am trying to make an explosion effect when an enemy in my game dies. i am using raycast shooting and damage scripts to attack and kill the enemies.
I’ve made a code to check if the enemy is dead and then Instantiate a particle system to the enemies position, but when i kill the enemy he just pops away rather than exploding. i am fairly new to programming so forgive my somewhat sloppy code.

#pragma strict

var Health = 100;
var Effect : Transform;

function Update () 
{
	if (Health <= 0)
	{
		Dead();}
}
function ApplyDamage (TheDamage : int)
{
Health -= TheDamage;
}
function Dead()
{
Destroy (gameObject);
}
if (Dead) {
	var boom = Instantiate (Effect, transform.position, transform.rotation);
	Destroy(boom.gameObject, 10);
	}

The problem is first, the if statement is out of a function; and second, you need to make sure that the particle is instantiated before the enemy is destroyed. Also, you do not need to check if health <= 0 in the Update(), instead you should do it after applying damage–in the apply damage function.

This code should fix the issue:

#pragma strict
 
 var Health = 100;
 var Effect : Transform;

function ApplyDamage (TheDamage : int)
{
    Health -= TheDamage;
    if (Health <= 0)
    { Dead(); }
}
function Dead()
{
    var boom = Instantiate (Effect, transform.position, transform.rotation);
    Destroy(boom.gameObject, 10);
    Destroy (gameObject);
}