Update javascript to catch undefined variable