Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript and the Illusion of Everything-as-an-Object

Sign upSign InSign upSign InMember-only storyRiccardo BertoliniFollowBits and Pieces--2ShareJavaScript is a remarkably one (if not “the”) most popular language used for web and server applications; it’s part of the ECMAScript standard, with each new specification introducing additional features, keeping it updated and adding new exciting features — however the chore, the hard base that makes Javascript so versatile, is it true it’s just objects made?The truth is both simple and intricate. At its core, JavaScript categorizes values into two types: primitive values and objects. Although JavaScript often seems a place where all values appear to act like objects, there are essential differences and specific situations where these differences matter.Primitives, or primitive values, are the fundamental data types in JavaScript that are not objects and do not have methods. JavaScript recognizes seven primitive data types: String, Number, BigInt, Boolean, Undefined, Null, and Symbol. If you’re using TypeScript you know what I’m talking about (or even PropTypes in React).While these primitive types don’t inherently possess properties or methods, JavaScript includes object equivalents — String, Number, BigInt, Boolean, and Symbol—that wrap around their respective primitive counterparts. This concept is called "boxing".In the code snippet above, str is a string primitive, and when we reference str.length then JavaScript automatically "boxes" str into a temporary String object, accesses the length property, and then discards the temporary object, creating the illusion of a primitive acting as an object. But in reality, it’s not!In contrast to primitives, objects in JavaScript represent collections of properties where each one is a connection between a key and a value. And here we all…----2Bits and PiecesCode lover, videogamer and amazing tiramisu maker!Riccardo Bertolini--6Robert Maier-SilldorffinBits and Pieces--8Osusara KammalawattainBits and Pieces--1Riccardo BertoliniinStackademic--The Deca Dose--1Agarwal Peeyush--Anisur Rahman--Shemeera Fonseka--1Dmitry KruglovinBetter Programming--43Manish Sharma--HelpStatusWritersBlogCareersPrivacyTermsAboutText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

JavaScript and the Illusion of Everything-as-an-Object

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×