Are you new to JavaScript? Know about these 7 features that are rare in other programming languages.
🧵 👇
1️⃣ undefined
2️⃣ Functions as first-class citizens
3️⃣ Closure
4️⃣ Prototypal Inheritance
5️⃣ Divide by Zero doesn't result into error
6️⃣ Array-Like
7️⃣ Strings are primitives
1️⃣ undefined
✪ Almost all languages have a special empty value which is called null, Null, None etc
✪ In addition to null, JavaScript also has one more: undefined
✪ If something is not known to exist, use "undefined". If something exists but its value is unknown, use "null"
2️⃣ Functions as first-class citizens
In JavaScript,
✪ Functions can be treated as values, i.e. can be stored as a value in a variable
✪ Functions can be passed as arguments to another function
✪ Functions can be returned from another function
Hence, first-class citizen.
3️⃣ Closure
✪ Variables can have scopes to be accessed inside a function only.
✪ Because functions are first-class citizens, an inner function can be defined inside any function.
✪ The inner function can access variables scoped to parent function which is known as "Closure"
4️⃣ Prototypal Inheritance
✪ All JavaScript objects inherit properties and methods from a prototype
✪ Prototype itself is an object which may inherit from another prototype
✪ When we read a property from object, and it's missing; it automatically takes it from the prototype
5️⃣ Divide by Zero doesn't result into error
✪ Many languages throw error when a number is attempted to be divided by Zero.
✪ But, JavaScript handles it other way. It results into NaN, Infinity or, -Infinity.
✪ Example
0 / 0 ⇨ NaN
1 / 0 ⇨ Infinity
-1/0 ⇨ -Infinity
6️⃣ Array-Like
✪ If an object has a "length" property and can be iterated, that's known as "Array-Like".
✪ If an object is "Array-Like", it can be used like an Array in many use cases.
✪ Example: strings are "Array-Like".
7️⃣ Strings are primitives
✪ Unlike many other languages, JavaScript treats strings as primitives. Where needed strings are auto converted to objects.
✪ Though there are ways to create Strings as Objects, but it's unnecessary and not recommended.
With this, we come to the end of this 🧵. Did you find it useful?
You can help in making this content reaches many
♥️ Like
🔁 RETWEET
💬 Reply
the very FIRST tweet in this 🧵
To never miss any content from me,
✅ Follow @swapnakpanda
🔔 Turn on Notifications
• • •
Missing some Tweet in this thread? You can try to
force a refresh