Martynas Kašelionis
WEB developeris, programavimo mokytojas
Parengė: Martynas Kašelionis
From zero to hero
Nauja versija, kuri turi daugiau lankstumo ir patobulintą sintaksę
console.log('string text line 1\n' +
'string text line 2');
// "string text line 1
// string text line 2"Old shool
ES6
console.log(`string text line 1
string text line 2`);
// "string text line 1
// string text line 2"var a = 5;
var b = 10;
console.log('Fifteen is ' + (a + b) + ' and\nnot ' + (2 * a + b) + '.');
// "Fifteen is 15 and
// not 20."Old shool
ES6
var a = 5;
var b = 10;
console.log(`Fifteen is ${a + b} and
not ${2 * a + b}.`);
// "Fifteen is 15 and
// not 20."Išraiškos
let [firstName, middleName, lastName] = ['Dylan', 'Coding God', 'Israel'];
lastName = 'Clements';
console.log(lastName)Masyvas
Objektas
const personalInformation = {
firstName: 'Dylan',
lastName: 'Israel',
city: 'Austin',
state: 'Texas',
zipCode: 73301
};
const {firstName: fn, lastName: ln} = personalInformation;
console.log(`${fn} ${ln}`);function addressMaker(city, state) {
const newAdress = {newCity: city, newState: state};
console.log(newAdress);
}Old shool
ES6
function addressMaker(city, state) {
const newAdress = {city, state};
console.log(newAdress);
}ES6
const array1 = ['a', 'b', 'c'];
for (const element of array1) {
console.log(element);
}const numbers = [1, 2, 3];
function sum(nums) {
console.log(nums);
}Problema
ES6
const numbers = [1, 2, 3];
function sum(...nums) {
console.log(nums);
}ES6
function sum(...nums) {
let total = nums.reduce((x, y) => x + y);
console.log(total);
}
sum(1,2,3);ES6
if(data.includes('Kazkas')){
console.log("Kontaktas surastas");
} else{
console.log("Kontaktas nerastas");
}let data = {
name:'John',
lastname: "Gates",
age: 37
}
export default {data};Export
Import
import data from 'data.js';
console.log(data);By Martynas Kašelionis