Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!