You will know how to **check if a number is a negative integer in Javascript** after this lesson. Follow the article below, I will share with you some useful ways.

**Check if a number is a negative integer in Javascript**

**Use the if-else conditional statement and isInteger() function**

To check whether a number is a negative integer, we have two things to do: check if the number is an integer or not and check if the number is negative. If these two conditions are satisfied, the number is a negative integer.

`isInteger()`

is a method in Number Object which checks whether an object is an integer or not.

**Syntax:**

`Number.Integer(num)`

**Parameter**:

**num**: is the object to check whether it is an integer. If the object is an integer, true is returned and false in all other cases.

However, the integer function cannot tell whether it is a positive or negative integer. So we have to combine the comparison of that number with `0`

.

**Code sample**:

```
function isNegativeInteger(number){
// Check integer and negative number
if(Number.isInteger(number) && number < 0){
console.log(number +' is a negative integer');
} else console.log(number +' is not a negative integer');
}
isNegativeInteger(9347562);
isNegativeInteger(-3284345);
isNegativeInteger(-3.9347);
isNegativeInteger(1.73486);
```

**Output**

```
9347562 is not a negative integer
-3284345 is a negative integer
-3.9347 is not a negative integer
1.73486 is not a negative integer
```

**Use the if-else conditional statement and Math.sign() function**

Instead of comparing the number with `0`

to check if the number is negative, we can use the Math.sign() function.

**Syntax**

`Math.sign(num)`

**Parameter**:

**num:** is the number to check whether it is negative.

- If the number is positive, returns 1.
- If the number is negative, returns -1.
- If the number is positive zero, returns 0.
- If the number is negative zero, return s-0.

**Code sample**:

```
function isNegativeInteger(number){
// Check integer and negative number
if(Number.isInteger(number) && Math.sign(number) == -1){
console.log(number + ' is a negative integer');
}else console.log(number +' is not a negative integer');
}
isNegativeInteger(4785);
isNegativeInteger(-32343);
isNegativeInteger(0.0004239);
isNegativeInteger(-0.0007241);
```

**Output**

```
4785 is not a negative integer
-32343 is a negative integer
0.0004239 is not a negative integer
-0.0007241 is not a negative integer
```

**Summary**

Above, I showed you how to **check if a number is a negative integer in Javascript** by two methods. I hope they are helpful to you. To better understand the lesson’s content, practice rewriting today’s examples. And let’s learn more about Javascript in the next lessons here. Have a great day!

**Maybe you are interested**:

- How to Check if a Value is a Number in JavaScript
- Check if a Character is a Number using JavaScript
- Check if String is a Positive Integer using JavaScript

Hi, my name is Joni Smith. My job is a programmer. I love learning programming languages, especially C++, C#, php, javascript, html, css. I want to share them with you. I hope my articles will bring a lot of useful knowledge to you.

**Name of the university: **HVNH BA

**Major**: htttql MIS

**Programming Languages**: C++, C#, php, javascript, html, css