JS must know topics

function handleChange(event) {
console.log(event.currentTarget.value);
// currentTarget is element on which event listener was added (input)
// here target is “form” since it is the actual element clicked
}
var formEls = document.getElementsByTagName(‘input’);
for (let i = 0; i < formEls.length; i++) {
formEls[i].addEventListener(‘change’, handleChange, false);
}
function handleChange(event) {
console.log(event.target);
// switch case for each target, target is actual element clicked (input)
}
var el = document.getElementById(‘form’);
el.addEventListener(‘change’, handleChange);
function foo() {
// I am a definition or statement
}
var foo = function foo() {
// I am an expression, I resolve to a value, even if just “undefined”
}
function foo() {
// won’t work: syntax error
}();
function foo() {
// won’t work: syntax error
}
(); // function with no nameanswer: ( function foo() {} )();
const foo = bar — 1; // bar is not defined error
foo = 7 // Valid, assinged to global/window
const foo = null;
console.log(foo) // null

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Priyanshu Chauhan

Priyanshu Chauhan

JS fan

More from Medium

Typescript vs. Javascript: The Key Differences You Should Know in 2022

TypeScript vs. JavaScript: The Key Differences You Should Know — Flatlogic Blog

React-router-dom— The essentials

An image of a map

Coding Conditionals

JavaScript Design Patterns #2: Open-Closed Principle

An example code snippet written in Javascript keeping the open-closed principle in mind.