Categories
JavaScript

call(), apply() and bind()

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()

Categories
JavaScript

The Ultimate JavaScript Mastery Series – Part 2

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 […]

Categories
JavaScript

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

Categories
JavaScript

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 […]

Categories
JavaScript Programming

The Ultimate JS Mastery Series – Part 1

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 […]

Categories
Basic JavaScript

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 […]

Categories
JavaScript

Prevent Page Scrolling Using JavaScript

Categories
JavaScript

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 […]

Categories
JavaScript

Get first word of a string

regular expression split() substr() https://stackoverflow.com/questions/18558417/get-first-word-of-string/18558427

Categories
JavaScript Vue.js

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