Use a compound assignment operator:

v += 4;
Answer from helpermethod on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Increment
Increment (++) - JavaScript - MDN Web Docs - Mozilla
July 8, 2025 - The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.
Discussions

How does this increment after 5 runs?
https://developer.mozilla.org/en-US/docs/Web/API/clearInterval and https://developer.mozilla.org/en-US/docs/Web/API/setInterval More on reddit.com
🌐 r/learnjavascript
4
2
July 23, 2023
variables - JavaScript incrementing by 0.5 - how? - Stack Overflow
I have a problem incrementing a number by 0.5. I've used "+=" operator but instead of incrementing my number, this adds "0.5" value in the end of number. The example is this: fu... More on stackoverflow.com
🌐 stackoverflow.com
Basic JavaScript: Increment a Number with JavaScript
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read · See this post to find the backtick on your keyboard. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
October 9, 2018
javascript - Increment HTML5 Number Field by .5 with step of .01 - Stack Overflow
I've got a number field that I use as a quantity value and I need values of the following format to be accepted by the field. 0.01 0.1 1 So I created my input field like so: More on stackoverflow.com
🌐 stackoverflow.com
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Increment a Number with JavaScript 5 - JavaScript - The freeCodeCamp Forum
November 7, 2018 - Tell us what’s happening: Your code so far var myVar = 87; // Only change code below this line myVar = 86 ;++myVar; myVar=myVar;++myVar Your browser information: User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64;…
🌐
W3Schools
w3schools.com › jsref › jsref_oper_increment.asp
JavaScript Increment Operator
let y = 5; let x = ++y; Try it Yourself » · The increment operator (++) adds 1 from the operand. If it is placed after the operand, it returns the value before the increment. If it is placed before the operand, it returns the value after the ...
🌐
Medium
medium.com › @ryan_forrester_ › incrementing-values-in-javascript-how-to-guide-ea389b4ea9fa
Incrementing Values in JavaScript (How to Guide) | by ryan | Medium
September 12, 2024 - You can use a for loop to iterate over the array and increment each element. let numbers = [1, 2, 3, 4, 5]; for (let i = 0; i < numbers.length; i++) { numbers[i]++; } console.log(numbers); // Output: [2, 3, 4, 5, 6]
🌐
Reddit
reddit.com › r/learnjavascript › how does this increment after 5 runs?
r/learnjavascript on Reddit: How does this increment after 5 runs?
July 23, 2023 -

Learning simple Javascript concepts using Pluralsight and I've stumbled upon a challenge that I don't fully understand. I get how this block of code works for the most part. What I can't figure out is how it is clearing the interval after it repeats the console.log() block 5 times. Can someone explain to me how this knows to increment the delay every 5 runs?

let lastIntervalId, counter = 5;

const greeting = delay => {

if (counter === 5) {

clearInterval(lastIntervalId);

lastIntervalId = setInterval(() => {

console.log('Hello World. ' + delay);

greeting(delay + 100);

}, delay);

counter = 0;

}

counter += 1;

};

greeting(100);

How I read this is counter is set to 5. The IF block is checking if the counter is set to 5 and running the code within it. It sets an interval, executes console.log, executes the greeting function again with a 100ms delay, which (in my mind) should loop things back to line 3 and start over indefinitely. How does it know to add another 100ms every 5th time? Thanks for the help!

Find elsewhere
🌐
Mimo
mimo.org › glossary › javascript › plus-plus-operator
JavaScript ++ Operator: Increment Values
The JavaScript plus plus operator is most useful in places where you need to increase a number by one without typing the longer form x = x + 1 or x += 1. Here are common situations where the ++ operator is helpful: The ++ operator is often used to increment the loop variable in a for loop.
🌐
CodeBurst
codeburst.io › javascript-increment-and-decrement-8c223858d5ed
JavaScript Increment ++ and Decrement -- | by Brandon Morelli | codeburst
December 12, 2017 - The increment and decrement operators in JavaScript will add one (+1) or subtract one (-1), respectively, to their operand, and then return a value.
🌐
W3Schools
w3schools.com › js › js_operators.asp
JavaScript Operators
let x = 5 + 5; let y = "5" + 5; let z = "Hello" + 5; ... If you add a number and a string, the result will be a string! Assignment operators assign values to JavaScript variables.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Basic JavaScript: Increment a Number with JavaScript - JavaScript - The freeCodeCamp Forum
October 9, 2018 - var myVar = 87; // Only change code below this line var myVar = myVar ++; var myVar = 88; but i keep getting this error message : / / running tests myVar = myVar + 1; should be changed // tests completed please h…
Top answer
1 of 2
6

Basically, you need to change its set value property between:

<input type="number" step=".01">

and

<input type="number" step=".5"> When the user clicks the up/down arrow or presses the up/down keys.

So, I've made an example in JavaScript to illustrate this particular scenario.

Something like this:

(function() {
  var numberFields = document.querySelectorAll("input[type=number]"),
    len = numberFields.length,
    numberField = null;

  for (var i = 0; i < len; i++) {
    numberField = numberFields[i];
    numberField.onclick = function() {
      this.setAttribute("step", ".5");
    };
    numberField.onkeyup = function(e) {
      if (e.keyCode === 38 || e.keyCode === 40) {
        this.setAttribute("step", ".01");
      }
    };
  }
}());
<input type="number" step=".01">

2 of 2
1

You can't do this with an number input, but with a text input, the magic happens...

I've styled it a bit so you can see when it's valid and invalid.

It is possible to use negative numbers in here, so if you want that I can edit it, but it gets a little wacky around -1 to 0.

let input = document.getElementById('addNum');
increment = 0.5;

input.onkeydown = function(e){
  if(e.key == "ArrowUp"){
    e.preventDefault();
    let value = +this.value;
    this.value = value + increment;
  } else if(e.key == "ArrowDown"){
    e.preventDefault();
    let value = +this.value;
    this.value = value - increment;
  }
}
input:valid {
  border-color: #0f0;
}
input:invalid {
  border-color: #f00;
}
input {
  outline: none;
}
Enter a (non-negative) number:
<input type="text" pattern="\d*[.]*\d{0,3}" id="addNum">

🌐
Rip Tutorial
riptutorial.com › incrementing (++)
JavaScript Tutorial => Incrementing (++)
The Increment operator (++) increments its operand by one. If used as a postfix, then it returns the value before incrementing. If used as a prefix, then it returns the value after incrementing. //postfix var a = 5, // 5 b = a++, // 5 c = a // 6
🌐
Codecademy
codecademy.com › forum_questions › 508fe06f900ba10200002d7f
the for loop increment | Codecademy
Interestingly, in section 2 of the “Art of Looping” lesson, the for loop’s increment section read as counter = counter + 1. That for loop ran fine: for (var counter = 1; counter <= 5; counter = counter + 1 )
🌐
Tutorial Gateway
tutorialgateway.org › increment-and-decrement-operators-in-javascript
Increment and Decrement Operators in JavaScript
March 28, 2025 - i– (Post decrement): The JavaScript operator returns the variable value first (i.e., i value), then only i value decrements by 1. This example will show you, How to use Increment and Decrement Operators as the Prefix and Postfix in JavaScript · <!DOCTYPE html> <html> <head> <title> javascript prefix and Postfix </title> </head> <body> <script> var x = 10, y = 20, a = 5, b= 4; document.write("<b>----PRE INCREMENT OPERATOR EXAMPLE---- </b>"); document.write("<br \> Value of X : " + x); //Original Value document.write("<br \> Value of X : "+ (++x)); // Using increment Operator document.write("
🌐
AlgoCademy
algocademy.com › link
Increment And Decrement Operators in JavaScript | AlgoCademy
The increment operator (++) increases the value of a variable by one, while the decrement operator (--) decreases the value of a variable by one. These operators can be used in two forms: postfix and prefix.