Composing Example
See the Pen ReactExample114 by kenanhancer (@kenanhancer) on CodePen.
Continue readingSee the Pen ReactExample114 by kenanhancer (@kenanhancer) on CodePen.
Continue readingSee the Pen ReactExample103 by kenanhancer (@kenanhancer) on CodePen.
Continue readingI don't know how to emphasise how much closures are important 🙂 but if you are not aware of it, you may face many unpredictable and unexpected issues in your code. Even you are aware of it, you may still have some logical problem due to "Function Closure"
Continue readingJava String is a sequence of characters.
Java String variable contains a collection of characters surrounded by double quotes.
An array of characters works same as Java String.
Java Strings are used for storing text.
In Java, Strings are immutable or final or constant which means each time when we are creating or editing or performing any method to change string, one string created in "String Constant Pool"
Immutable strings eliminate race conditions in multi-threaded applications.
There are two ways to create a String object:
String str1 = "Hello World!";
String str2 = "Hello World!";
Each time you create a string literal, the JVM checks the "string constant pool" first. If the string already exists in the pool, a reference to the pooled instance is returned. If the string doesn't exist in the pool, a new string instance is created and placed in the pool.
In other words, we don't create any String object using new keyword above. The JVM does that task for us, it create a String object. If the String object exist in the memory, it doesn't create a new String object rather it assigns the same old object to the new instance, that means even though we have two String instances above(str1 and str2) compiler only created one String object and assigned the same to both the instances.
For example there are 5 String instances that have same value, it means that in memory there is only one String object having the value and all the 5 String instances would be pointing to the same String object.
What if we want to have two different String object with the same String. For that we would need to create Strings using new keyword
String str1 = new String("Hello World!");
String str2 = new String("Hello World!");
In such case, the JVM will create a new String object in normal (non-pool) heap memory.
Notice that JVM handles allocation of memory space for string variables efficiently, whenever we create a String variable and assign a String value with String Literal(double quotes) , JVM check value of String variable in String pool, if found, it returns reference of String object, if not found then it creates a new String object in String pool and return reference of it.
I found some images from google to represent. So, there are three images below.
Continue readingIn order to find more details about this
usage, follow link below.
https://www.w3schools.com/Js/js_this.asp
I just took the following part from that page.
Continue readingI try to understand difference between function expression
, shorthand method definition
, arrow function
and bind()
.
Notice that I defined sayGoodBye()
function in constructor, it means that whenever i create a new instance from this Person
class, sayGoodBye()
function will be defined for every instance.
sayHello()
function is defined as a class property. But, as you can see in the following screenshot, class properties are also defined in constructor so class properties are just a sugar syntax.
getFullName()
function is defined as shorthand method definition. But, Babel didn't move function definition in class constructor. So, if we use shorthand method definition in class, it will be a prototype function .
It mean they are only defined once, instead of once per instance.
Notice that in below screenshot, getFullName()
function is in prototype of Person class, but sayHello()
and sayGoodBye()
are not.