Geek Culture
Published in

Geek Culture

7 Javascript Concepts to Master Before Any Framework / Library

A simple guide to essential modern JavaScript

Photo by Eric & Niklas on Unsplash

1. Understand “let” and “const”

var userName = 'John';
console.log(userName);
userName = 'Doe';
console.log(userName);
let userName = 'John';
console.log(userName);
userName = 'Doe';
console.log(userName);
const userName = 'John';
console.log(userName);
userName = 'Doe';
console.log(userName);
TypeError: Assignment to constant variable.

2. Arrow Functions and how to use them

function doSomething() {
// some more logic...
}
var doSomething = function() {
// Some more logic ...
}
const doSomething = () => {
// Some more logic...
}
function printUserName(userName) {
console.log(userName);
}
printUserName('John');
const printUserName = (userName) => {
console.log(userName);
}
printUserName('John');
const printUserName = userName => {
console.log(userName);
}
printUserName('John');
const printUserName = () => {
console.log('John');
}
printUserName();
const printUserName = (userName, age) => {
console.log(userName, age);
}
printUserName('John', 28);
const squared = number => number ** 2; 
console.log(squared(3));

3. Learn Exports⁶ and Imports⁷ for Modular code

Created by author
import {clean, baseData} from './utility.js'
import person from './person.js'
import prs from './person.js'
import {clean} from './utility.js'//also use an alias
import {clean as cln} from './utility.js'
//or import everything with * with an alias and use it as bundled.clean
import * as bundled from './utility.js'

3. Understand Classes⁸

class Person {
name = 'John'
call = () => {// Some logic...}
}
const myPerson = new Person()
myPerson.call()
console.log(myPerson.name)
class person extends Human
class Person {
constructor() {
this.name = 'John';
}
printMyName() {
console.log(this.name);
}
const person = new Person();
person.printMyName();
class Human {
constructor () {
this.gender = 'male';
}
printGender() {
console.log(this.gender);
}
}
// Inherit from Human Class
class Person extends Human {
constructor() {
super();
this.name = 'John';
}
printMyName() {
console.log(this.name);
}
const person = new Person();
person.printMyName();
person.printGender();

4. Use NextGen Properties and Methods in Classes

constructor () {
this.myProperty = 'value'
}
myProperty = 'value'
myMethod () {...}
mymethod = () => {...}
class Human {
gender = 'male';
printGender = () => {
console.log(this.gender);
}
}
// Inherit from Human Class
class Person extends Human {
this.name = 'John';
printMyName = () => {
console.log(this.name);
}
const person = new Person();
person.printMyName();
person.printGender();

5. The helpful Spread¹¹ & Rest¹² Operators

const newArray = [...oldArray, 1,2]
const newObject = {...oldObject, newProp: 3}
const sortArgs  = (...args) => {
return args.sort()
}

6. Destructuring¹³

[a,b] = ['Hello','John']
console.log(a) // prints Hello
console.log(b) // prints John
{name} = {name:'John', age:28}
console.log(name) // Prints John
console.log(age) // undefined

7. Refreshing Primitive¹⁴ and Reference¹⁵ Types

const number = 5
const num2 = number
console.log(num2) // prints 5
const person = {
name = 'John'
}
const secondPerson = person;
console.log(secondPerson); // prints same vale as person
const secondPerson = person;
person.name = 'Doe'
console.log(secondPerson); // prints same value as updated person
const person = {
name = 'John'
};
const secondPerson = {
...person
};

Conclusion

Resources

--

--

A new tech publication by Start it up (https://medium.com/swlh).

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
Shashank Katte

Full-Stack Developer and Agile-DevOps Coach from Toronto. I write about programming, technology and leadership | katte.io