Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Literals and Variable declaration
- * Arrow Function
- * ES6 Classes , Object destrucing
- * Async Programing - Classbacks, Promises
- * Modularity - Es6 Modules
- */
- /**
- * How to declare variable
- * 1.var => ES%
- * 2. let and const => ES6
- * var variablename = value(literals)
- * // number,string,boolean,undefined,infinity,NAN,function,null,object
- */
- let city = 'Chennai';
- console.log("Name:" + city)
- console.log(`City: ${city}`)
- console.log(
- `
- helloo
- hi
- sample
- here
- `
- )
- /**let htmlDoc = "<html>" +
- "<body>" +
- "<h1>" +
- "Hello" +
- "</h1>" +
- "</body></html>"*/
- //multiline: es 6
- let htmlDocEs6 = `<html>
- <body>
- <h1>
- Hello
- </h1>
- </body>
- </html>
- `
- console.log(htmlDocEs6)
- let price = 100;
- console.log(`Price Given : ${price}`);
- let isActive = true;
- console.log(`Status Given : ${isActive}`);
- let qty;
- console.log(`Quantity : ${qty}`);
- let totalprice = price*qty;
- console.log(`Total Price : ${totalprice}`)
- let gst = "10";
- let totalInvoice = parseFloat(gst) * 8/100;
- console.log(`Print Invoice : ${totalInvoice}`);
- /**
- * 1.boolean Flase
- * "", '' (Empty String)
- * undefined
- * 0
- * null
- * NAN
- */
- if(isActive){
- console.log("Status is Active")
- }else{
- console.log("Status is not Active")
- }
- let name = "ram";
- if(name){
- console.log("person is present");
- }else{
- console.log("person is not present");
- }
- // Mostly in react constants are used
- const pi = 3.14;
- console.log(`PI : ${pi}`);
- //pi = 30;
- /**
- * Function
- *
- */
- function add(){
- console.log("this is a function to add");
- }
- // Invoke Function
- add()
- // a, b are arg
- // default args
- function add_something(a=1,b=2){
- const result = a+b;
- console.log(result);
- }
- //5, 6 are parameter , any literals can be passed
- add_something(5,6);
- add_something(5);
- add_something();
- add_something("sample", "hi")
- function logger(screen,...args){
- console.log(screen, args);
- }
- //req for logger : Paramter Dynamic
- logger("dashboard", "hi");
- logger("Home", "hi", "hello")
- //return types
- function do_login(username, password){
- /* if(username === "admin" && password === "admin"){
- return true;
- }
- return; */
- return (username === "admin" && password === "admin") ? true : false
- }
- do_login('admin', 'admin') ? console.log('Valid User') : console.log('Unauthenticated User');
- /**
- * Arrow Functions
- * -> can assign function to variable
- * -> can be returned from another function
- * -> can be passed as parameter to another function
- */
- // How to assign a function to a variable
- //var/let/const
- /**
- * Function can be assigned to var
- * that var can be used to an function
- */
- const add = function(a,b){
- console.log(a+b);
- return a+b;
- }
- var sample = add(1212,6);
- console.log(sample)
- /**
- * Arrow Function
- */
- let do_multiply = (a,b) =>{
- console.log(a*b);
- }
- do_multiply(5,6)
- //if function has no body , only one line , we can remove {}
- const do_division = (a,b) => {return a/b};
- console.log(do_division(100,5))
Add Comment
Please, Sign In to add comment