This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
function Example() { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
document.title = `You clicked ${count} times`; | |
}, [count]); // Only re-run the effect if count changes | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
function Example() { | |
const [count, setCount] = useState(0); | |
// count is state variable | |
// setCount is method to update the count. | |
// 0 is the default value of count | |
return ( | |
<button onClick={() => setCount(count + 1)}> Click me </button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
function UVHeader(props: any) { | |
return ( | |
<div className="uv-header-container"> | |
<span>{props.data.title}</span> | |
</div> | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Mobile = function(size) { | |
this.displaySize = size; | |
}; | |
var Tablet = function(size) { | |
this.displaySize = size; | |
}; | |
var Desktop = function(size) { | |
this.displaySize = size; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = function(personName) { | |
var age = 30; // age will not be accessible outside of Person block | |
var name = 'Yuvraj'; | |
function getName() { | |
return name; | |
} | |
// This return code block is more clean than that of module pattern | |
return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = function(personName) { | |
var age = 30; // age will not be accessible outside of Person block | |
var name = 'Yuvraj'; | |
return { | |
getName: function() { | |
return name; | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Cricketer = function(name, runs) { | |
this.name = name; | |
this.runs = runs; | |
}; | |
Cricketer.prototype.getPlayerDetails = function() { | |
return this.name + ' has scored ' + this.runs + ' runs'; | |
} | |
var player1 = new Cricketer('Sachin', 18426); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = function(personName) { | |
this.name = personName; | |
}; | |
var person1 = new Person('Yuvraj'); | |
var person2 = new Person ('Arya'); | |
console.log(person1.name); // Yuvraj | |
console.log(person2.name); // Arya |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TaskManager = (function(){ | |
var taskManager = null; | |
function createInstance(id) { | |
if(taskManager === null) { | |
taskManager = new Object(); | |
taskManager.id = id; | |
return taskManager; | |
} | |
return taskManager; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(isVisible) { | |
console.log('We should use the braces even if there is only one statement in block'); | |
} |