Learning javascript properly