Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
How to check empty in variable in Google Apps Script

I have a variable that can be either empty, number or text. I like to find only empty one. But the following codes using .length returned null for 0 number, though it returned 1 for "0" string . .toString.length even didn't work. Any suggestion? Thank you!

function test() {
  // criteria can be either empty, number or text. How can I check whether the critieria is empty?
  // In the example below, critiera_2.length returned null, not 1.
  criteria_1 = "";
  Logger.log(criteria_1.length);
  criteria_2 = 0;
  Logger.log(criteria_2.length);
  criteria_3 = "0";
  Logger.log(criteria_3.length);
  criteria_4 = "X";
  Logger.log(criteria_4.length);


  criteria_1 = "";
  Logger.log(criteria_1.toString.length);
  criteria_2 = 0;
  Logger.log(criteria_2.toString.length);
  criteria_3 = "0";
  Logger.log(criteria_3.toString.length);
  criteria_4 = "X";
  Logger.log(criteria_4.toString.length);
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

criteria_1 = "";
console.log(criteria_1.toString() == ''); // output: true

const test = x => console.log(x.toString()==='');

test("");  // true
test(0);   // false
test("0"); // false
test("X"); // false

It's turned out that you don't even need toString() it could be just x===''

about 4 years ago · Juan Pablo Isaza Relatório

0

To check for an empty string, a simple approach would be to use === operator

if (criteria_1 === "") {
    //...
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda