The provided web content is a comprehensive guide on JavaScript programming, covering terms, syntax, and features from ECMAScript 5 and 6, including functions, objects, strings, arrays, maps, sets, ES6 modules, and control structures, with practical examples and explanations.
Abstract
The article serves as an educational resource for developers seeking to understand and utilize JavaScript effectively. It begins by distinguishing between JavaScript and ECMAScript, then delves into the specifics of JavaScript syntax, including the introduction of ES6 features such as arrow functions, promises, and classes. The guide also covers practical aspects of JavaScript programming such as object creation, string templating, array manipulation, and the use of data structures like maps and sets. Additionally, it touches on advanced topics such as promises for asynchronous operations and the use of ES6 modules for better code organization. The article aims to be a one-stop reference for both novice and experienced developers to enhance their JavaScript skills.
Opinions
The author, Sean, positions himself as both a learner and a teacher, offering his notes on JavaScript as a means to assist others while also inviting feedback for improvement.
There is an emphasis on the practical application of JavaScript concepts, with the author providing real-world examples and encouraging hands-on practice.
The article suggests that understanding the JavaScript Runtime and how JavaScript works is a prerequisite for effectively writing JavaScript programs.
The author expresses a preference for ES6 features, highlighting their advantages, such as the concise syntax of arrow functions and the improved readability of template literals.
Sean advocates for the use of modern JavaScript practices, including the use of let and const for variable declarations, and the adoption of Promise and async/await for handling asynchronous code.
The guide promotes the idea that mastering JavaScript syntax and features, such as destructuring and the spread operator, can lead to writing more efficient and maintainable code.
By providing links to related topics and encouraging subscription to his Facebook page, the author indicates a commitment to
How does JavaScript work? Part 2. The terms and syntax (includes ES5 and ES6)
Introduction
In the previous article, I mentioned the JavaScript Runtime and how does it work.
The next stage for us is how do we write a JavaScript program? This topic is my note for learning some basic terms and syntax like Function, Object, String, Array, Map, Set, ES6 module.
I expect it will be helpful to you!
ECMAScript, JavaScript, ES5, and ES6?
That’s declare these common terms before we dive into the JavaScript syntax.
ECMAScript: it’s a standard and a specification published by Ecma International.
JavaScript: it’s an implementation of ECMAScript.
ES5 (ECMAScript5): The version 5 of ECMAScript. Here are some major features in ES5.
- 1. strict mode
- 2. object methods
- 3. array methods
ES6 (ECMAScript6/ ECMAScript2015): The version 6 of ECMAScript. Here are some major features in ES6.
- 1. Arrow function
- 2. Rest operator
- 3. Spread operator
- 4. Object literal shorthand
- 5. String template/Template literals
- 6. Array destructuring
- 7. Default parameters
- 8. Object literal
- 9. Promises
- 10. Class
- 11. const & let
The following table shows browsers’ compatibility for ES6.
constbuildHouse = ({floors = 1, color = 'red', walls = 'brick'} = {}) => `Your house has ${floors} floor(s) with ${color}${walls} walls.`
Pure function
A function where the return value is only determined by its arguments without any side effects
Arrow function (ES6)
Advantages
The syntax is short
Easier to write and read short, single-line functions
Automatically return when using concise body syntax
Properties
Arrow functions are only expressions
Arrow functions inherit their this value from their surrounding context
Can’t use the arrow function as a constructor
Convert a function to an arrow function
Arrow functions are very similar to regular functions in behavior, but quite different syntactically.
Concise body syntax
Has no curly braces surrounding the function body
Automatically return the expression
const upperizedNames = ['Farrin', 'Kagure', 'Asser'].map(
name => name.toUpperCase()
);
Block body syntax
Use curly braces to wrap the function body
Use return statement to return something from the function
const upperizedNames = ['Farrin', 'Kagure', 'Asser'].map( name => {
name = name.toUpperCase();
return`${name} has ${name.length} characters in their name`;
});
Curry function
const multiArgFunc = (a, b, c) => a + b + c;
const curryUnaryFunc = a => b => c => a + b + c;
curryUnaryFunc(1);
curryUnaryFunc(1)(2);
curryUnaryFunc(1)(2)(3);
Arguments and Rest operator (ES6)
Turn all input parameters to a list
//ES5functionsum() {
var numbers = Array.prototype.slice.call(arguments)
}