-
-
Save sriniind19/eedfb769ac5e883a6dc848a863f57857 to your computer and use it in GitHub Desktop.
JavaScript New Points
This file contains 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
// To identify the time consumed by the functions | |
console.time('Performance'); | |
// Logic | |
console.timeLog('Performance'); | |
--- | |
// const dt = new Date(2021, 11, 13); --> 11 is 12th month, Month starts from 0 | |
--- | |
// To get the button name | |
<button type="button">Click Me!</button> | |
document.body.addEventListener('click', (event) => { | |
if(event.target.nodeName) { | |
console.log('Button Clicked.'); | |
} | |
}); | |
--- | |
Broadcast Channel API - | |
References: | |
https://www.youtube.com/watch?v=wYcvzLFHFN0&ab_channel=dcode | |
https://pbs.twimg.com/media/FGjTL81XMAEb3vm?format=jpg&name=medium | |
--- | |
// Destructuring Array into Object - | |
const countries = [ | |
'India', | |
'USA', | |
'Canada', | |
'UK' | |
]; | |
const { 0: ind, 2: can} = countries; | |
console.log(ind, can); | |
--- | |
// Creating Own Custom HTML Element - | |
<body> | |
UI | |
<my-element/> | |
</body> | |
<script> | |
class MyElement extends HTMLElement { | |
connectedCallback() { | |
this.innerHTML = 'This is a custom elment'; | |
} | |
} | |
customElements.define('my-element',MyElement); | |
</script> | |
--- | |
* typeof null will be object | |
* typeof (typeof 1) will be String | |
* typeof !!-1 will be Boolean | |
* typeof function(){} will be function | |
* typeof new Date() will be object | |
* typeof [] will be object | |
--- | |
* Number(undefined) will be NaN | |
* Number(null) will be 0 | |
* Number('text') will be NaN | |
* Number(true) will be 1 | |
* Number(false) will be 0 | |
* Number([]) will be 0 | |
* Number(["10"]) will be 10 | |
* Number(["10", "20"]) will be NaN | |
--- | |
true == "true" will be false | |
false == "false" will be false | |
100 == "100" will be true | |
-0 === 0 will be true | |
Object.is(-0,0) will be false | |
-10 === 10 will be false | |
NaN === NaN will be false | |
Object.is(NaN, NaN) will be true | |
* Object.is is a better way to compare | |
--- | |
"hello" > "Hello" will be true as the ASCII code of h is greater than H | |
"h".charCodeAt() give the ASCII code | |
--- | |
Hoisting a concept due to this all variables are evaulation on top of the file - | |
console.log(num); | |
const num = 10; | |
Note: You don't see error due to Hoisting | |
--- | |
' I am human '.trimStart(); --> Remove space in start | |
' I am human '.trimEnd(); --> Remove space in end | |
---*** All Useful References ***--- | |
Tips: https://twitter.com/SimonHoiberg/status/1470657546776154112 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment