typeOf

typeOf

> Funzioni

Restituisce il tipo del valore valore, tra i tipi:

Impostazioni
Feedback
TypeScript

In JavaScript, typeof value restituisce una stringa — "number", "string", "boolean", "function", "object", "undefined" — e non una costante numerica come typeOf in LeekScript. Due trappole classiche: typeof [] e typeof null valgono entrambi "object". Usate Array.isArray(value) per riconoscere un array, value === null per null, e instanceof per il resto: value instanceof Map, value instanceof Cell, value instanceof Entity.

Python

In Python, type(value) restituisce la classe del valore e non una costante numerica come typeOf in LeekScript: type([]) vale `, e type(value).__name__ dà "list", "bool", "Cell"… Per verificare un tipo, scrivete sempre isinstance(value, list) piuttosto che type(value) is list: il motore avvolge list, dict, set, tuple e frozenset per contare le operazioni, cosicché type([]) is list vale False mentre isinstance([], list) vale True. isinstance accetta per giunta una tupla di tipi, isinstance(x, (int, float))`, e riconosce le sottoclassi.