Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Type Utilities - JavaScript Challenges

Introduction Checking types is a common practice in JavaScript in everyday coding and technical interviews. You can find all the code in this post at Github. Primitive values In JavaScript, all types except Object define…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




Introduction



Checking types is a common practice in JavaScript in everyday coding and technical interviews.



You can find all the code in this post at Github.









Primitive values



In JavaScript, all types except Object define immutable values represented directly at the lowest level of the language. We refer to values of these types as primitive values.



There are 7 primitive values:




  1. Null

  2. Undefined

  3. Boolean

  4. Number

  5. BigInt

  6. String

  7. Symbol



All primitive types, except null, can be tested by the typeof operator. typeof null returns "object", so one has to use === null to test for null.



Therefore, we get the first type utility function.




function isBoolean(value) {
return typeof value === 'boolean';
}

function isString(value) {
return typeof value === 'string';
}

function isNumber(value) {
return typeof value === 'number';
}

function isSymbol(value) {
return typeof value === 'symbol';
}

function isBigInt(value) {
return typeof value === 'bigint';
}

function isUndefined(value) {
return typeof value === 'undefined';
}

function isNull(value) {
return value === null;
}

// Usage example
console.log(isSymbol(Symbol('test'))); // => true
console.log(isNull(null)); // => true
console.log(isUndefined(undefined)); // => true
console.log(isNumber(1)); // => true
console.log(isString('')); // => true
console.log(isBoolean(true)); // => true
console.log(isBigInt(9007199254740991n)); // => true












Objects



Everything that's not a primitive type is an object in JavaScript. This includes:




  • Plain objects

  • Arrays

  • Functions

  • Dates

  • RegExps

  • Other built-in object types



Here comes the second utility function for Arrays, Functions, Objects.




function isArray(value) {
return Array.isArray(value);
}

function isFunction(value) {
return typeof value === 'function';
}

function isObject(value) {
// for null and undefined
if (value == null) {
return false;
}

return typeof value === 'object';
}

function isPlainObject(value) {
// for null and undefined
if (value == null) {
return false;
}

const prototype = Object.getPrototypeOf(value);
return prototype === Object.prototype || prototype === null;
}

// Usage example
console.log(isArray(new Array())); // => true
console.log(isObject(Object(null))); // => true
console.log(isFunction(Object.prototype.toString)); // => true
console.log(isPlainObject(Object.create(null))); // => true












Object.prototype.toString.call()



There are several methods to check types in JavaScript, including:





  • typeof for all the primitive types except null.


  • instanceof determines whether an object is an instance of a specific constructor or class. It does not work with primitive values.



Object.prototype.toString.call() is the most reliable method for type checking in JavaScript.



We can extract the types by:




function getType(value) {
const type = typeof value;

if (type !== 'object') {
return type;
}

return Object.prototype.toString
.call(value)
.slice(8, -1)
.toLowerCase();
}

// Usage example
console.log(getType(1)); // => number
console.log(getType('')); // => string
console.log(getType({})); // => object
console.log(getType(null)); // => null
console.log(getType(undefined)); // => undefined
console.log(getType(Symbol())); // => symbol
console.log(getType(BigInt(1234567890123456789012345))); // => bigint
console.log(getType(function () {})); // => function
console.log(getType(new Date())); // => date
console.log(getType(new Map())); // => map
console.log(getType(new Set())); // => set
console.log(getType(new RegExp("cat", "i"))); // => regex












Reference



Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Type Utilities - JavaScript Challenges

Thematisch verwandte Begriffe: Type, Utilities, JavaScript, Challenges · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-49449 | Joplin is an open source note-taking and to-do application that organise…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick