Consider this JavaScript snippet:
var a = document.createElement("a");
a.style.display = "none";
IntelliJ IDEA 2016.2 highlights a.style.display
and gives this hint:
Value assigned to primitive will be lost
Checks for improper usage of wrappers for JavaScript primitive types. Also, warning will be produced when property of primitive type is modified, as assigned value will be lost
CSSStyleDeclaration
is not a primitive type, thus the assignment to display
won't be lost.
String
is a wrapper type. How am I using it (improperly)?
The code seems to work fine in Chrome and Edge. What's the deal?
Default Values Assigned to Primitive Data Types in Java Data Type Size Byte 1 byte Short 2 bytes Int 4 bytes Long 8 bytes 4 more rows ...
In HTML, the default display property value is taken from the HTML specifications or from the browser/user default style sheet. The default value in XML is inline, including SVG elements. ? The numbers in the table specify the first browser version that fully supports the property.
More "Try it Yourself" examples below. The display property specifies the display behavior (the type of rendering box) of an element. In HTML, the default display property value is taken from the HTML specifications or from the browser/user default style sheet.
However, relying on such default values is not considered a good programming style. Now as we know Initializing a variable means to give an initial value to a variable before using it.
There's nothing improper in your code, IntelliJ's type inference is getting a bit confused (this aspect of JavaScript is particularly confusing).
Its linter sees a string and assumes you will try something like this:
var primitive = "september";
primitive.vowels = 3;
primitive.vowels;
// => undefined
Which would lead to a 'lost' value.
To further understand this weird part of JavaScript, I recommend Angus Croll's excellent in-depth article here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With