Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:02:39+00:00 2026-06-02T00:02:39+00:00

Im currently in process of learning Javascript. And I have seen the following code,

  • 0

Im currently in process of learning Javascript. And I have seen the following code, which confuses me.

Description of code:
Starting on line 1, the function isOdd takes a number n and returns a boolean (true or false) stating whether the number is odd or not.

Code

var isOdd = function (n) {
      if (n % 2 === 0) {
        return false;
      } else {
        return true;
      }
    };

    var isEven = function(n) {
        if(n % 2 === 0) {
            return true;
        } else {
            return false;
        }
    };

Where I am confused.
The code:

n % 2 === 0

I have always taken the following to be the description for %:

% Is the modulus operator. It returns the remainder of dividing number1 by number2.

Which would mean that the if statement in the function isOdd returns false is the difference between n and 2 is 0. But its meant to mean if n is divisible by 2 (even) return false.

I just dont see how its doing that.

In my mind, if we take the even number 30. Apply it to n % 2. We get 15, which is remainder of dividing 30 by 2. 15 does not equal 0, but 30 is an even number, and with this code it would be seen as odd.

Can someone explain this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:02:40+00:00Added an answer on June 2, 2026 at 12:02 am

    The line in question:

      if (n % 2 === 0) {
        return false;
      }
    

    Means “if when you divide n by 2 the remainder is zero, then return false (i.e. n is not odd)”.

    The “remainder” is whatever is left over when you subtract the nearest multiple, so for example “64 % 10” is 4, since the nearest multiple of 10 is 60, leaving 4.

    Taking your example and putting it another way, 30/2 is 15, 30%2 is zero (i.e. whatever is left over after 30/2). Here’s more info on the remainder after division.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've got a process currently which causes ASP.NET websites to be redeployed. The code
I am currently in the process of learning Ruby on Rails. I have been
We currently have a process where we receive an inventory file from a vendor
I am currently in the process of porting game code from PC to flash,
I am currently in the process of learning Struts 2 and I am currently
I'm in the process of learning WPF and am currently looking into application commands
I'm currently in the process of learning ASP MVC and am running into a
I'm currently in the process of learning ssh via the brute-force/ just keep hacking
I am in the process of learning Backbone.js. I currently assume that if one
I am currently in the process of learning the CodeIgniter PHP framework. At the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.