https://stackoverflow.com/a/54562241 call and apply call a function while bind creates a function. Use .bind() when you want that function to later be called with a certain context, useful in events. Use .call() or .apply() when you want to invoke the function immediately, and modify the context. call() & apply()
Category: JavaScript
Getting started OOP (Object-oriented programming) A programming paradigm centered around objects rather than functions 4 pillars Encapsulation Related variables and functions are combined into an objects variables => properties functions = > methods Abstraction Benefits: Simpler interface Reduce the impact of change Inheritance A way to eliminate redundant code Polymorphism Encapsulation Reduce complexity + increase […]
typeof
The typeof operator returns a string indicating the type of the unevaluated operand. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
console.log()
The console.log() method outputs a message to the web console. Syntax console.log(obj1 [, obj2, …, objN]);console.log(msg [, subst1, …, substN]); Output single value / object Note: what you get logged on the console is a reference to the object, which is not necessarily the ‘value’ of the object at the moment in time you call console.log(), but it is […]
Getting Started JavaScript ranks first place in the most popular technologies at Stack Overflow for year 2020 Where does JavaScript code run? JavaScript Engine in browsers (originally for frontend) FireFox: SpiderMonkey Chrome: v8 Node (runtime environment for backend) a C++ program include Google’s v8 JavaScript engine Difference between ECMAScript & JavaScript ECMAScript: specification JavaScript programming […]
Testing in JS
What is “Testing”? We have expected result of our code, and testing is to make sure that the expectation is achieved, otherwise modification should be done. Instead of manually do it, we prefer to automate and simplify the process. Why Test? Get an error in case break code save time think about possible issues and […]
Detect Element Visibility
There are two ways to know when an element gets visible / hidden in the screen during scrolling: Listening to the window scroll event Observing the element for visibility using Intersection Observer API Listening to the scroll Event Attach a scroll event handler to the window object, and use getBoundingClientRect() to calculate the position of […]
Get first word of a string
regular expression split() substr() https://stackoverflow.com/questions/18558417/get-first-word-of-string/18558427
Vue.js Directives
click-outside https://stackoverflow.com/a/42389266 Bonus: add tabindex attribute to enable element to be focused https://stackoverflow.com/a/53956904