Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Javascript purpose of return false in this code?

Attachment image

2 Answers

Relevance
  • 6 years ago

    As I said in the comment above, a function by default returns 'undefined', which for all intents and purposes is the same as returning false. So the return false here is essentially useless.

    MORE:

    Why is returning 'false' the same as returning 'undefined'? This has to do with the concept of 'truthiness' in JavaScript: certain values, when evaluated as 'yes' or 'no', will evaluate to true. For example:

    0 = false

    false = false (duh)

    "false" = true (it's a string, so the browser thinks it exists, and therefore is true)

    "any other string" = true

    1 to infinity, or -1 to negative infinity = true

    undefined = false

    null = true (usually!)

    So if a program were to use this return value to test something (i.e., if (!showpic(myObj)) alert('returned false!')), returning false would do the exact same thing as returning nothing (i.e., undefined).

  • 6 years ago

    it get back to your code and from where you call JS function

Still have questions? Get your answers by asking now.