Why is typeof null “object”?

From the MDN page about the behaviour of the typeof operator: null // This stands since the beginning of JavaScript typeof null === ‘object’; In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0. null was represented as the NULL pointer … Read more

Async function returning promise, instead of value

Async prefix is a kind of wrapper for Promises. async function latestTime() { const bl = await web3.eth.getBlock(‘latest’); console.log(bl.timestamp); // Returns a primitive console.log(typeof bl.timestamp.then == ‘function’); //Returns false – not a promise return bl.timestamp; } Is the same as function latestTime() { return new Promise(function(resolve,success){ const bl = web3.eth.getBlock(‘latest’); bl.then(function(result){ console.log(result.timestamp); // Returns a … Read more

Why don’t Java Generics support primitive types?

Generics in Java are an entirely compile-time construct – the compiler turns all generic uses into casts to the right type. This is to maintain backwards compatibility with previous JVM runtimes. This: List<ClassA> list = new ArrayList<ClassA>(); list.add(new ClassA()); ClassA a = list.get(0); gets turned into (roughly): List list = new ArrayList(); list.add(new ClassA()); ClassA … Read more