Guest User

Untitled

a guest
Oct 8th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. /**
  2. * Literals and Variable declaration
  3. * Arrow Function
  4. * ES6 Classes , Object destrucing
  5. * Async Programing - Classbacks, Promises
  6. * Modularity - Es6 Modules
  7. */
  8.  
  9. /**
  10. * How to declare variable
  11. * 1.var => ES%
  12. * 2. let and const => ES6
  13. * var variablename = value(literals)
  14. * // number,string,boolean,undefined,infinity,NAN,function,null,object
  15. */
  16.  
  17. let city = 'Chennai';
  18. console.log("Name:" + city)
  19. console.log(`City: ${city}`)
  20. console.log(
  21. `
  22. helloo
  23. hi
  24. sample
  25. here
  26. `
  27. )
  28. /**let htmlDoc = "<html>" +
  29. "<body>" +
  30. "<h1>" +
  31. "Hello" +
  32. "</h1>" +
  33. "</body></html>"*/
  34.  
  35. //multiline: es 6
  36. let htmlDocEs6 = `<html>
  37. <body>
  38. <h1>
  39. Hello
  40. </h1>
  41. </body>
  42. </html>
  43. `
  44. console.log(htmlDocEs6)
  45.  
  46. let price = 100;
  47. console.log(`Price Given : ${price}`);
  48.  
  49. let isActive = true;
  50. console.log(`Status Given : ${isActive}`);
  51.  
  52. let qty;
  53. console.log(`Quantity : ${qty}`);
  54.  
  55. let totalprice = price*qty;
  56. console.log(`Total Price : ${totalprice}`)
  57.  
  58. let gst = "10";
  59. let totalInvoice = parseFloat(gst) * 8/100;
  60. console.log(`Print Invoice : ${totalInvoice}`);
  61.  
  62. /**
  63. * 1.boolean Flase
  64. * "", '' (Empty String)
  65. * undefined
  66. * 0
  67. * null
  68. * NAN
  69. */
  70.  
  71. if(isActive){
  72. console.log("Status is Active")
  73. }else{
  74. console.log("Status is not Active")
  75. }
  76.  
  77. let name = "ram";
  78. if(name){
  79. console.log("person is present");
  80. }else{
  81. console.log("person is not present");
  82. }
  83.  
  84. // Mostly in react constants are used
  85.  
  86. const pi = 3.14;
  87. console.log(`PI : ${pi}`);
  88. //pi = 30;
  89.  
  90. /**
  91. * Function
  92. *
  93. */
  94.  
  95. function add(){
  96. console.log("this is a function to add");
  97. }
  98.  
  99. // Invoke Function
  100. add()
  101. // a, b are arg
  102. // default args
  103. function add_something(a=1,b=2){
  104. const result = a+b;
  105. console.log(result);
  106. }
  107. //5, 6 are parameter , any literals can be passed
  108. add_something(5,6);
  109. add_something(5);
  110. add_something();
  111. add_something("sample", "hi")
  112.  
  113. function logger(screen,...args){
  114. console.log(screen, args);
  115. }
  116. //req for logger : Paramter Dynamic
  117. logger("dashboard", "hi");
  118. logger("Home", "hi", "hello")
  119.  
  120. //return types
  121.  
  122. function do_login(username, password){
  123. /* if(username === "admin" && password === "admin"){
  124. return true;
  125. }
  126. return; */
  127. return (username === "admin" && password === "admin") ? true : false
  128. }
  129.  
  130. do_login('admin', 'admin') ? console.log('Valid User') : console.log('Unauthenticated User');
  131.  
  132. /**
  133. * Arrow Functions
  134. * -> can assign function to variable
  135. * -> can be returned from another function
  136. * -> can be passed as parameter to another function
  137. */
  138.  
  139. // How to assign a function to a variable
  140. //var/let/const
  141. /**
  142. * Function can be assigned to var
  143. * that var can be used to an function
  144. */
  145.  
  146. const add = function(a,b){
  147. console.log(a+b);
  148. return a+b;
  149. }
  150. var sample = add(1212,6);
  151.  
  152. console.log(sample)
  153.  
  154. /**
  155. * Arrow Function
  156. */
  157.  
  158. let do_multiply = (a,b) =>{
  159. console.log(a*b);
  160. }
  161.  
  162. do_multiply(5,6)
  163.  
  164. //if function has no body , only one line , we can remove {}
  165.  
  166. const do_division = (a,b) => {return a/b};
  167. console.log(do_division(100,5))
Add Comment
Please, Sign In to add comment