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

198
Views
Need clarification as to why code is correct
const isString = (a, b, c) => {
  if (((typeof a) == "string") && ((typeof b) == "string") && ((typeof c) == "string")) {
    return "strings";
  }
  return "not strings";
}

Why is the => after the argument required in order for this to work? I got this test question correct via trial and error, but I don't understand why it doesn't work without =>.

Here are the instructions.

Create a function called "isString" that takes 3 arguments (x1, x2, x3)

  • Check if each argument is a string using typeof.
  • If each argument is a string, return "strings".
  • If each argument is NOT a string, return "not strings".
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

The => is the syntax for an arrow function

about 4 years ago · Juan Pablo Isaza Report

0

The => operator is required because that is how javascript's syntax for anonymous functions works. This is creating a function equivilent to isString(a,b,c) {...}. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

about 4 years ago · Juan Pablo Isaza Report

0

Assuming that this is javascript, the => is indicating that it is part of an Arrow Function. The following two codes are equivalent as for the understanding of the two.

// function declaration
function isString (a, b, c) {
  if (((typeof a) == "string") && ((typeof b) == "string") && ((typeof c) == "string")) {
    return "strings";
  }
  return "not strings";
}
// arrow function declaration; can also use `var` instead of `const`
const isString = (a, b, c) => {
  if (((typeof a) == "string") && ((typeof b) == "string") && ((typeof c) == "string")) {
    return "strings";
  }
  return "not strings";
};
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!