Just Learn Code

Mastering the Basics of JavaScript: Understanding Encoding Semicolons and Identifiers

JavaScript is one of the most commonly used programming languages in the world. It’s used for a wide variety of purposes, including creating interactive web pages, developing mobile applications, and building server-side applications.

Despite its popularity, there are still many aspects of JavaScript that developers may not fully understand. In this article, we’ll cover the basics of JavaScript, including encoding, semicolons, case sensitivity, white spaces, literals, and identifiers.

We’ll also take a look at some of the reserved words in ES5 and ES6.

JavaScript Encoding

Unicode is the standard for encoding text. Unicode assigns every character a unique number, which makes it possible to use any character from any writing system in any other system without any problems.

Chinese and Japanese are among the many languages that use Unicode. One of the challenges with Chinese and Japanese characters is that they can’t be represented in a single byte, which makes it difficult to store them in computers.

This is where Unicode comes in. By using Unicode, characters from any writing system can be stored and used in JavaScript without any problems.

Use of Semicolons

ECMAScript, the standardized version of JavaScript, requires the use of semicolons to terminate statements. Semicolons are used to separate statements and to indicate the end of a statement.

However, JavaScript does allow you to omit semicolons in certain circumstances. For example, if a new line is followed by a parenthesis, bracket, or curly brace, the semicolon is automatically inserted.

While you can omit semicolons, it’s generally considered best practice to include them in your JavaScript code.

Case Sensitivity

JavaScript is case sensitive, which means that string “String” is different from string “string”. This also applies to comments “THIS IS A COMMENT” is not the same as “this is a comment”.

It’s important to keep this in mind when working with JavaScript, as it can lead to unexpected results if you’re not careful.

White Spaces

White spaces, such as tabs, spaces, and line breaks, are not significant in JavaScript. However, it’s considered good practice to indent your code properly and use a linter or beautifier to automatically format your code.

This makes it easier to read and understand your code, and it makes it easier to spot errors.

Literals

Literals are values that are written directly into your code, such as strings, numbers, and booleans. String literals are enclosed in quotes, number literals are simply numbers, and boolean literals are either true or false.

Array literals are lists of values enclosed in square brackets, and object literals are sets of key-value pairs enclosed in curly braces. Null is a special literal that represents a null or empty value.

Identifiers

Identifiers are names that you give to variables, functions, classes, modules, and other constructs in JavaScript. It’s important to avoid using reserved words as identifiers, as this can lead to errors and unexpected behavior.

Reserved words are keywords that are part of the JavaScript language and cannot be used as identifiers. Some examples of reserved words in ES5 include “char” and “default”, while ES6 reserved words include “async” and “let”.

ES5 / 5.1 Reserved Words

ES5 and 5.1 are versions of ECMAScript, which is the standardized version of JavaScript. These versions have a number of reserved words, which are words that cannot be used as variable names or property names.

Some of the reserved words in ES5 include “break”, “case”, “char”, “continue”, “default”, and “do”. ES6 / 2015 Reserved Words

ES6, also known as ECMAScript 2015, introduced a number of new features to JavaScript, including arrow functions, classes, let and const, and templates literals.

ES6 also has a number of new reserved words, such as “await”, “async”, “let”, and “yield”. In conclusion, these are just some of the basics of JavaScript.

Understanding how encoding works, knowing when to use semicolons, being aware of case sensitivity and white spaces, and using literals and identifiers correctly are all important skills for any JavaScript developer. Knowing the reserved words in ES5 and ES6 is also important to avoid errors and ensure compatibility with different browsers and platforms.

As you continue to work with JavaScript, you’ll discover many more tips and tricks that will make your code cleaner, more efficient, and more maintainable. In conclusion, this article explored the basics of JavaScript, including encoding, semicolons, case sensitivity, white spaces, literals, and identifiers.

We also looked at some of the reserved words in ES5 and ES6. Understanding these concepts is essential for any developer who wants to create high-quality JavaScript code.

By following the best practices outlined in this article, such as using semicolons and avoiding reserved words, developers can write more efficient and maintainable code. With these foundational skills firmly in place, developers can confidently explore more advanced features of JavaScript and continue to expand their coding abilities.

Popular Posts