1οΈβ£ Primitive vs Object Type
2οΈβ£ Auto Convertible
3οΈβ£ Immutable
4οΈβ£ Easily Comparable
5οΈβ£ Array-Like
6οΈβ£ Spreadable
7οΈβ£ Possible to Destructure
1οΈβ£ Primitive vs Object Type
βͺ In JavaScript, a string value can either be a primitive or, an object.
βͺ What is Primitive?
A primitive is a data that is not an object and has no methods.
1οΈβ£.1οΈβ£ String Primitives
βͺ String Primitives are created either by using String Literals or, String function [String()].
βͺ A String Primitive has a separate data type: "string"
1οΈβ£.1οΈβ£.1οΈβ£ String Literals
βͺ What is a String Literal?
String literals can be specified using single quotes ( ' ) or double quotes ( " ) or back tick characters ( ` ).
Example: π
1οΈβ£.1οΈβ£.2οΈβ£ String Function
βͺ String function can be called in a non-constructor context (i.e., without using the new keyword).
βͺ This basically is used to convert data of other types to string.
βͺ After conversion, it returns a string literal.
Example: π
1οΈβ£.2οΈβ£ String Objects
βͺ String primitives have a wrapper equivalent.
βͺ String objects can be created using constructor of String type i.e., new String()
βͺ It is mostly discouraged to create String objects manually as they mostly operate as wrappers of primitives.
2οΈβ£ Auto Convertible
βͺ In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the String primitive to a String object.
βͺ And then call the method or perform the property lookup on the object.
3οΈβ£ Immutable
βͺ By immutable, it means the original value (or, content) cannot be altered.
βͺ Strings are immutable in JavaScript.
βͺ None of the methods or, properties can alter the original string. When required to alter, they return a new string.
Example: π
4οΈβ£ Easily Comparable
βͺ In JavaScript, string literals can easily be compared using comparison operators like ==, !=, <, <=, >, >=.
Example: π
5οΈβ£ Array-Like
βͺ An Array-Like looks like an Array. It has a length property. It's iterable. And, its elements can be accessed using indexes.
βͺ In JavaScript, strings are not real arrays, rather just array-like.
Example: π
6οΈβ£ Spreadable
βͺ Like an array, a string can also be used along with spread operator [...]
βͺ Spread Operator Assignment returns a new array of all characters in the string.
Example: π
7οΈβ£ Possible to Destructure
βͺ Like an array, a string can also be destructured.
Let's see π
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
β C/C++
β Java
β Python
β JavaScript
Or, any language of your choice
Stay in top 5% of programmers.
β Arrays
β Creating an Array
β Iterate through Array
β Get an Element
β Search an Element
β Insert Element(s)
β Delete Element(s)
β Filter an Array
β Fetch a Sub-Array
β Merging Arrays
β Reverse Array
ββ Rotate Array
β Linked Lists
β Creating a Linked List
β Iterate through Linked List
β Get an Element
β Find an Element
β€ Insert Element(s)
β At Start
β At End
β At Anywhere
β€ Delete Element(s)
β From Start
β From End
β From Anywhere
ββ IsEmpty
ββ Merging Linked Lists
ββ Reverse Linked List
ββ Check for Cycles
Implement these algorithms for linked lists, double linked lists, circular linked lists, etc.