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

103
Visualizações
Create a function which accepts an argument from input textbox and returns the type of the value in javascript

I am not able to determine the exact typeof value in input text box.

Argument

JS Code

function typeOfArgument()
{
    let argument = document.getElementById("argument").value;

    let typeOfArgument = typeof(argument)
    document.getElementById("mypara").innerHTML = "type of "+argument+" is "+typeOfArgument;
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

function typeOfArgument() {
    let argument = document.getElementById("argument").value;
    let typeOfArgument = "string";
    
    try{
        if (argument === "undefined") {
            typeOfArgument = "undefined"
        }
        else if(argument === "null" || JSON.parse(argument).constructor === Object || JSON.parse(argument).constructor === Array)
        {
            typeOfArgument = "object";
        }
        else if (!isNaN(parseInt(argument))) {
            typeOfArgument = "number";
        }
        else if(argument === "true" || argument === "false") 
        {
            typeOfArgument = "boolean"
        }
        document.getElementById("mypara").innerHTML = "type of " + argument + " is " + typeOfArgument;
    }
    catch(e)
    {
        console.log("exception")
        document.getElementById("mypara").innerHTML = "type of " + argument + " is " + typeOfArgument;
    }
}
<p>Enter argument</p>
<label>Argument</label>
<input type="text" id="argument"/>
<br/>

<button onclick="typeOfArgument();">Submit</button>
<p id="mypara">The output will be displayed here</p>

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