Modern JavaScript Concepts

let name = "Kasun";
let age = 25;
let desc = "My name is "+name+" and my age is "+age;
console.log(desc);
printNames();
let fName = "Chamara";
let lName = "Fernando";
let fullName = `My first name is ${fName} and my last name is ${lName}`;
console.log(fullName);
function myMarks(...marks){    
console.log(marks);
}
myMarks(60,50,88,77,81);
//output
[60,50,88,77,81]
let a = [1,2,3,4,5];
let b = [6,7,8,9];

// Make one array using 2 arrays
let c = [...a, ...b];

console.log(c);
console.log(...c);//output[1,2,3,4,5,6,7,8,9]1 2 3 4 5 6 7 8 9
let fullName = ["Kasun", "Darshana", "Perera"]; console.log(fullName);
console.log(...fullName); // Split array content
//output ["Kasun", "Darshana", "Perera"]
kasun Darshana Perera
let subject = "Science"; 
console.log(subject);
console.log(...subject); // Seperate a string
//output
Science
S c i e n c e
let subject = {maths : 80,science: 66 }
let personal = {
name : 'Dasun',age : 24,...subject // Spread an object }
console.log(subject);
console.log(personal);//output{ maths: 80, science: 66 }{ name: 'Dasun', age: 24, maths: 80, science: 66 }
// -----Function Declaration-----
function myAge(age){
console.log(`My age is ${age}`);
}
myAge(23);// -----Function Expression-----const myName = function(name){console.log(`My name is ${name}`);}myName("Dasun");
const subject = () => {
return "Maths"
}
subject();
const std = {name : "Chamara Silva",degree : "BSc Comp Sc.",age : 25,subjects : ["Java", "OS", "Comp Design", "Networking"],gpa : {first : 3.8,second : 3.6,third : 3.4}}
const {name,age} = std;console.log(`My name is ${name}.My age is {age}`);
const {degree:d, age:a} = std;const {name:n,age:a} = std;console.log(`My name is ${n}.My age is {a}`);
const names = ["Sanduni", "Chamara", "Sajith"];const [n1, n2, n3] = names;console.log(n1);console.log(n2);console.log(n3);
//output
Sanduni
Chamara
Sajith

--

--

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