JSFiddle - React, Tailwind, and code Playground
JavaScript
//Function declaration
console.group('Function declaration');
console.log('We can access the function declaration definition from anywhere in the scope ->');
functionDeclaration();
function functionDeclaration() {
console.log('Function declaration');
}
console.groupEnd();
// Function expression
console.group('Function expression');
console.log('Now you\'ll see the error, as variable functionExpression is not assigned to the function expression just yet');
try {
functionExpression();
} catch(e) {
console.log('Here is the error: ', e, ' , as functionExpression is ', functionExpression, ' sorry');
}
var functionExpression = function() {
console.log('Function expression!');
}
console.log('Now functionExpression has a value of -> ');
console.log(functionExpression);
console.log('So we can now call it: ');
functionExpression();