Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

333
Vistas
Is there a way to disable Global Variable Declaration within Function

I ran into a issue eventually it turned out because I did not use var prefix during declare a local variable within a function, so when it get to next function it actually automatically pick it up the variable, even though that was a syntax mistake as my initial intent is to use another local variable with similar name. So is there a setting on google apps script to throw error on a global variable declaration within function to avoid this kind of tricky issues?

Here is sample code of my problematic issue

function f1(){
   for(var idx=0;idx<length; idx++){
     tmp1 = idx;  // since tmp1 missing var, it endup as global variable
     ...
   }
}
function f2(){
   Logger.log(tmp1);// even though I did not delcare tmp1 here, it will not throw either validation nor runtime error.
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use the JavaScript strict mode. To do this, add the following at the global scope:

'use strict';

The above string literal could be added on any file in your Google Apps Script project, just be sure to add it outside of any function. In order to make this easier to find, add it on top of your project's first file.

Resources

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Related

  • Enforcing strict mode in google-apps-script files using Chrome on Chromebook
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda