Praleisti ir pereiti prie pagrindinio turinio

ES6: Default parameters

ES6 atsirado galimybė nurodyti reikšmę pagal nutylėjimą.

Turime situaciją (pvz):
function labas(user, message){
alert(`Labas ${user}. ${message}`);
}
labas('Vytautas','Sėkmingai prisijungėte!');
labas();



Pirmu atveju gausime tai ko ir tikimės:
Bet antru atveju (aišku galima su IF ar kitaip išspręsti šia smulkmeną):
ES6 leidžia nurodyti reikšmes pagal nutylėjimą:

function labas(user = 'Smitas', message = 'Dirbate neprisijungęs!'){
alert(`Labas ${user}. ${message}`);
}
labas('Vytautas','Sėkmingai prisijungėte!');
labas();

Antru atveju gausime tokį atsakymą:
Kadangi nenurodėme jokių parametrų, naršyklė panaudojo numatytąsias reikšmes.

Komentarai

Populiarūs šio tinklaraščio įrašai

React: Material Design for Bootstrap 4

https://mdbootstrap.com 1.  create-react-app yourappnamehere 2.  cd yourappnamehere 3. Add  mdbreact  as a dependency to the package.json (the  #react-upgrade  one) 4.  yarn  /  npm  shall install all the dependencies. Note, that  mdbreact  itself includes Bootstrap ( 4.0.0-beta.2 ) as its dependency. Once all of it is out of the way, 5. time to modify your  App.js  file. To utilize full power of  MBD React  there, you need to import components you would like to use, for example import {Button, NavbarBrand, Navbar, NavbarNav, NavItem} from 'mdbreact'; and secondly, you need proper CSS files. As MDB partially builds upon Bootstrap, it's safest to include both: import '../node_modules/bootstrap/dist/css/bootstrap.min.css'; import '../node_modules/mdbreact/docs/css/mdb.min.css'; As you can see, there is no jQuery involved. The warning popping out during  npm install  /  yarn stems ...

String sudėjimas

String 'sudėjimas' - sujungimas dviejų (arba bent vieno ir kito number) string duomenų. Pvz: "Labas"+"Lietuva" "Labas" + " Lietuva" "Dabar" + 20+17 "Dabar" + " 20"+"17"