perfect js code