37

What is the point to change (int) 1000 to 1E3?

And where does 1E3 come from?

I know just 3bytes vs 4bytes.

BetterLateThanNever
  • 886
  • 1
  • 9
  • 31
l2aelba
  • 21,591
  • 22
  • 102
  • 138
  • 8
    1E3 is notation for the mathematical expression 10^3 which is the same as 1000. If you wrote a million 1E6 would be 1000000 and then you would save two more bytes. – mortb Sep 03 '14 at 13:49
  • 1
    @mortb "1E6" saves _two_ more bytes compare to what? – Cœur Aug 13 '17 at 03:46
  • 2
    @Cœur yes I was wrong saying "two more bytes". It should be three more bytes. 1000 -> 1E3 saves one byte/character, 1000000 -> saves 1E6 saves four charactes, which is three more bytes. – mortb Aug 14 '17 at 07:23

3 Answers3

49

The whole point of minification is to be able to pass less data over the network but retain the same functionality.

Taken from wikipedia:

Minification (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments, and sometimes block delimiters, which are used to add readability to the code but are not required for it to execute.

As long as the size is smaller the minification is doing its job.

1E3 pretty much means 10 to the power of 3; a shorter way of representing the number 1000.

Community
  • 1
  • 1
Lix
  • 47,311
  • 12
  • 103
  • 131
  • I was looking at my code (handling time calculations) wondering why the heck I would have used 1e3 instead of 1000 and realized I was looking at the minified code and not the original source. – Dave Romsey Feb 12 '21 at 22:06
14

they are the same value, 1E3 is 10 to the third power, or 1000, so the point it so save 25%

PA.
  • 28,486
  • 9
  • 71
  • 95
12

To be precise: 1e3 stands for 1 * 10^3

Further Examples: 2e2 = 200 and 0.1e2 = 10

See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates

codebreach
  • 2,155
  • 17
  • 30
Momme Kuesel
  • 121
  • 1
  • 4
  • You can also achieve the same result by the infix operator in ES6. `10**3` is `1000` however this doesn't occupy less bytes compared to the `e` notation. – nullspace Nov 16 '20 at 07:14