DEV Community

Vijay SRJ
Vijay SRJ

Posted on

How does Number data type differ in Java and Javascript?

Brendan Eich , while creating Javascript took a great influence from Java.
In fact he was asked to create the Java language on the browser by the company Netscape.

So though Javascript has a lot of similarities with Java , it varies widely in other aspects.

With respect to numbers , Javascript treats Numbers differently from Java in these ways:

  1. All numbers are floating point numbers in Javascript
  2. You can represent 'Not a Number' in Javascript
  3. You can represent Infinity in Javascript
  4. You can convert a string to number using the '+' symbol in Javascript.

Explained with examples here:

Top comments (0)


11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!