Short answer
A data type is the kind of value a name can hold, and it also limits what you can do with that value. Oracle's Java tutorial says the type sets which values a name may contain. MDN says a JavaScript name is not tied to one value type, so it can later hold a different kind of value. ECMAScript 2025 lists Boolean, String, Number, BigInt, and Object. Java lists eight primitives and treats String as a class.
Last verified against the sources listed below.
Key takeaways
- Java is statically typed. You declare a variable's type and name before you use it.
- JavaScript is dynamically typed. One variable can be reassigned from a number to a string.
- Java's boolean type has only true and false. A field with no value defaults to false.
- JavaScript's typeof null is the string object. Test null with strict equality.
- Java's int is a 32-bit signed value from -2^31 to 2^31-1. The tutorial also notes an unsigned use.
- The Java tutorial says not to use float or double for currency. Use BigDecimal.
What is data type, on the Java and JavaScript pages opened here, is the kind of value a name can hold. Oracle’s tutorial says that type also decides the operations you may perform. MDN says JavaScript does not lock a variable to one type.
The two languages use the same English words for different rules. The table later in this guide lists only types those pages actually show.
JavaScript is one of the languages.
A programming paradigm is the broader style of writing, and a type rule is one concrete piece of that style.
What does a data type decide?
A data type decides which values a name may hold and which operations are allowed. The Java tutorial says the language is statically typed, so all variables must be declared before they are used. The declaration states the type and the name.
The tutorial’s example is int gear = 1. That line says a field named gear exists, holds numerical data, and starts at 1. A primitive type is predefined by the language and named by a reserved keyword. Primitive values do not share state with other primitive values.
JavaScript, on MDN’s page, is dynamic. Variables are not directly associated with any particular value type, and any variable can be assigned and reassigned values of all types. The page shows one name holding 42, then the string bar, then true. The type is a property of the current value, not a permanent label on the name.
How does JavaScript type its values?
JavaScript types are either primitives or Object, and MDN says every type except Object is an immutable primitive. The ECMAScript 2025 specification has headings for Undefined, Null, Boolean, String, Symbol, Number, BigInt, and Object. MDN’s typeof table matches those names.
typeof null returns the string object, so a null test uses strict equality. Every primitive except null and undefined has an object wrapper. Reading a property wraps the primitive, then reads the property. Reading a property of null or undefined throws a TypeError.
JavaScript is also weakly typed, so an operation on mismatched types may convert a value instead of throwing. MDN’s example adds the number 42 and the string “1”, and the result is the string 421. Symbols and BigInts disallow some of those implicit conversions on purpose.
Undefined means no value, and null means no object. A return with no value, a missing property, and a let with no initializer all produce undefined.
How does Java type its values?
Java’s eight primitive types are fixed at the declaration, and the tutorial lists a size or a value set for each. The page was written for JDK 8. It says the examples do not take advantage of later releases, and it still notes unsigned int and long behavior from Java SE 8 onward.
byte is an 8-bit signed integer from -128 to 127, and short is 16-bit, from -32,768 to 32,767. int is 32-bit signed, from -2^31 to 2^31 - 1. In Java SE 8 and later, Integer methods can treat an int as unsigned, from 0 to 2^32 - 1.
long is 64-bit, from -2^63 to 2^63 - 1, with an unsigned form from 0 to 2^64 - 1 through Long methods.
float is a 32-bit IEEE 754 value, and double is 64-bit IEEE 754, the usual choice for decimal numbers. The tutorial says the ranges live in the Java Language Specification and does not print them. It says never to use float or double for precise values such as currency, and to use java.math.BigDecimal instead.
boolean is only true or false. char is one 16-bit Unicode character, from \u0000 (0) to \uffff (65,535 inclusive).
String is not a primitive. A double-quoted literal creates a String object, and String objects are immutable. The tutorial says people often think of String as a primitive because the language gives it special support. The chart of defaults still lists String with the objects.
| Type | Page | What that page says |
|---|---|---|
| boolean | Java tutorial | Only true and false. A field defaults to false. |
| Boolean | MDN | Primitive. typeof returns boolean. Wrapper type Boolean. |
| int | Java tutorial | 32-bit signed, from -2^31 to 2^31 - 1. |
| Number | MDN and ECMAScript 2025 | typeof returns number. The spec has a Number type. |
| String | Java tutorial | A class, not a primitive. Immutable. |
| String | MDN | A primitive. typeof returns string. |
| BigInt | MDN and ECMAScript 2025 | typeof returns bigint. Some implicit conversions are disallowed. |
| char | Java tutorial | 16-bit Unicode, from 0 to 65,535 inclusive. |
What are the defaults, and where do they fail?
Java gives defaults to fields, and it refuses to invent a value for a local variable. The tutorial’s chart is byte, short, and int 0, long 0L, float 0.0f, double 0.0d, char \u0000, boolean false, and String or any object null. Relying on those defaults is called bad style.
Local variables are the sharp edge. The compiler never assigns a default to an uninitialized local variable. If you do not set it at the declaration, you must assign it before you read it. Copying the field-default chart onto a local variable is not what the page says.
JavaScript’s gap is different. A declared variable with no initializer is undefined, not a Java-style 0 or false. And because the language will convert types, a number plus a string can succeed and still be the wrong operation. MDN says those coercions cause subtle bugs when the conversion direction is not the one you expected.
The px to rem converter only does arithmetic on the numbers you type. It does not declare a Java variable or a JavaScript binding.
An HTML a element is not a data type either. The HTML standard says an a element with an href is a hyperlink, which is a document node, not a Java primitive or a JavaScript language type.
Which mix-up do the two pages make easy?
The mix-up is expecting Java’s declaration rule inside JavaScript, or JavaScript’s conversion rule inside Java. In Java, the type is part of the declaration, and a local variable with no value is an error, not undefined. In JavaScript, the same name can hold a number and later a string, and 42 plus “1” becomes “421” without a type error.
A second mix-up is treating Java’s String as one of the eight primitives. The tutorial says it is a class, that the objects are immutable, and that the special syntax makes it feel primitive. MDN’s String is a primitive with a wrapper, so the names match and the categories do not.
A third mix-up is using float or double for money because they are numeric. The Java tutorial says not to, and it points to BigDecimal. It also leaves the floating-point ranges to the language specification, so this guide does not fill those ranges in. The integer bounds above are the ones the tutorial prints.
Frequently asked questions
What is a data type?
It is the kind of value a name can hold, plus the operations that value allows. Oracle's Java tutorial says the language is statically typed, so every variable is declared with a type and a name before it is used. Declaring int gear = 1 says gear holds a number and starts at 1. MDN describes JavaScript differently: a variable is not tied to one value type, and it can be reassigned values of all types. The kind of value can change without renaming the variable.
What is the boolean data type?
In Java, boolean has only two values, true and false, and the tutorial says to use it for simple flags. It represents one bit of information, but its size is not precisely defined. A boolean field that is not initialized defaults to false. In JavaScript, MDN lists Boolean as a primitive whose typeof result is the string boolean, with a Boolean object wrapper. The languages share the name and the true-or-false idea. They do not share Java's rule that the type is fixed when the name is declared.
What is a data type in Java?
The Java tutorial lists eight primitive types: byte, short, int, long, float, double, boolean, and char. A primitive is predefined by the language and named by a reserved keyword, and primitive values do not share state. String is not a primitive. It is a class, and String objects are immutable. The tutorial was written for JDK 8 and says its examples skip later improvements. It does note that Java SE 8 and later can treat int and long as unsigned through methods on Integer and Long.
Why does adding a number and a string not fail in JavaScript?
MDN says JavaScript is weakly typed, so it allows implicit conversion when an operation mixes types, instead of throwing a type error. The page's example is a number 42 plus the string 1. JavaScript turns 42 into a string and concatenates, and the result is the string 421. That is convenient and easy to misread. The same page says symbols and BigInts intentionally disallow some of those implicit conversions. Java, being statically typed, does not use this example. A Java variable already has a declared type.
Do Java fields get a default value?
Fields that are declared and not initialized get a default. The tutorial's chart says byte, short, and int default to 0, long to 0L, float to 0.0f, double to 0.0d, char to the character \u0000, boolean to false, and String or any object to null. Local variables are different. The compiler never assigns a default to an uninitialized local variable. You must assign one before you use it. Relying on field defaults is described as bad style, even though the defaults exist.
Sources
- JavaScript data types and data structures · MDN, 2026
- Primitive Data Types · Oracle, 2026
- ECMAScript 2025 Language Specification · TC39, 2025
- HTML Standard, the a element · WHATWG, 2026