Java Script ES6

const and let

ES5
var example1 = document.getElementById('example1')
ES6
const example2 = document.getElementById('example2')
let name = "Soner"
name = "George"
console.log(name)
//output ---> George

Arrow functions

//ES5
function myFunction(name) {
return 'Hello' + name;
}
console.log(myFunc('Soner'))
//output
//Hello Soner
const myFunc = name => {
return `Hi ${name}`
}
console.log(myFunc('Soner'))
//output:Hi Soner
//or even without using arrow or implement `return` keyword const myFunc = name => `Hi ${name}`
console.log(myFunc('Soner')//
//output: Hi Soner
//ES5
const array=[ 'John','Jenny','Billy',5]
let Arr1 = array.map(function(item) {
return item;
});
console.log(Arr1);
//output (4) ['John','Jenny','Billy',5]ES6 Syntax let Arr2 = array.map(item => item );
console.log(Arr2)
output (4) ['John','Jenny','Billy',5]

Template Literals

//ES5
function myFunc1(name,age){
return 'Hi' + name + 'Your age is' + age + 'year old';
}
console.log(myFunc1('Soner', 40))
//output --> Hi Soner, Your age is 40 year old.
const myFunc =(name,age)=>{
return `Hi ${name}, Your age is ${age} years old!`;
}
console.log(myFunc('Soner', 40))
//output--> Hi Soner, Your age is 40years old

Default parameters

const myFunc =(name,age)=>{
return `Hello ${name} you age is ${age} years old?`
}
console.log(myFunc('Soner'))
//output: Hello Soner your age is undefined years old
const myFunc =(name,age=40 )=>{
return `Hello ${name} you age is ${age} years old?`
}
console.log(myFunc('Soner'))
//output: Hello Soner your age is 40 years old?

Array and object destructing

//ES5 syntax 
const contacts = {
name: 'Soner',
lastName:'Mezgitci',
age: 40
}
let name = contacts.name;
let lastName = contacts.lastName;
let myAge = contact.age;
console.log(name)
console.log(lastName)
console.log(myAge)
//output
Soner
Mezgitci
40
const contacts = {
name:'Soner',
lastName:'Mezgitci'
age:40
}
let{name,lastName,age} =contacts
console.log(name)
console.log(lastName)
console.log(age)
output:
Soner
Mezgitci
40
//ES6
const contacts={
name : 'Soner',
lastName:'Mezgitci',
age: 40
}
let{name:otherName,lastName,age} = contacts
console.log(otherName)
output:
Soner
const Arr=['Emre','Mert','Gina',35];
let [value1,value2,value3] =Arr;
console.log(value1)
console.log(value2)
console.log(value3)
//output
//Emre
//Mert
//Gina

Import and export

//ES6
export default function detail(name,age){
return `Hello ${name}, your age is ${age} years old!`;
}
import detail from './detailComponent'
console.log('Soner', 40))
//output: Hello Soner, your age is 40 years old!
import{detail,userProfile, getPosts} from './detailComponent'console.log(detail('Soner', 40))
console.log(userProfile)
console.log(getPosts)

--

--

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
Soner Mezgitci

Soner Mezgitci

31 Followers

Software Engineer | Ruby on Rails | JavaScript | HTML5 | CSS | PostgreSQL | React | Redux