A brief introduction to JavaScript

JavaScript was born in 1995. Its primary purpose is to handle input validation operations that were previously the responsibility of server-side languages such as Perl.

JavaScript’s evolution from a simple input validator to a powerful programming language is a complete surprise. It should be said that it is both a very simple language and a very complex language. It’s easy because it only takes a moment to learn how to use it. It’s complicated because it takes years to really master it. The key to fully understanding and mastering JavaScript is to understand its nature, history, and limitations.

JavaScript is a scripting language designed for interacting with web pages and consists of three distinct parts:

  • ECMAScript, defined by ECMA-262, provides core language functionality;
  • Document Object Model (DOM), which provides methods and interfaces for accessing and manipulating web content;
  • The Browser Object Model (BOM) provides methods and interfaces for interacting with the browser.

All three components of JavaScript are supported to varying degrees in the current five major browsers (IE, Firefox, Chrome, Safari, and Opera). Support for ECMAScript version 3 is generally good across all browsers, and support for ECMAScript 5 is growing, but DOM support varies considerably. While certain well-known common features are implemented across browsers in the BOM, which is officially incorporated into the HTML5 standard, others vary from browser to browser.

2. Basic concepts

grammar

ECMAScript’s syntax borrows heavily from C and other C-like languages such as Java and Perl. As a result, developers familiar with these languages should feel at ease when accepting ECMAScript’s looser syntax.

1 Variable names, function names, and operators are case sensitive

2 The first character of the identifier must be a letter, underscore (_), or a dollar sign ($). Other characters can be letters, underscores, dollar signs, or digits.

3 Comments Single-line comments start with two slashes, block-level comments start with a slash and an asterisk (/*), and end with an asterisk and a slash (*/)

// Single-line comment /* * This is a multi-line (block-level) comment */Copy the code

4 Strict Mode To enable strict mode throughout the script, add the following code at the top:

"use strict"; 
Copy the code

You can also specify that the function executes in strict mode by including this compilation instruction above the inside of the function:

function doSomething(){ "use strict"; // Function body}Copy the code

In strict mode, JavaScript execution results can be quite different, so this book will point out the differences in strict mode at any time. the

Browsers in strict mode include Internet Explorer 10+, Firefox 4+, Safari 5.1+, Opera 12+, and Chrome.

Statements in ECMAScript end with a semicolon; If the semicolon is omitted, the end of the statement is determined by the parser

Keywords and reserved words

Ecma-262 describes a set of keywords that have a specific purpose, such as to indicate the beginning or end of a control statement, or to perform a specific operation. By rule, keywords are also language reserved and cannot be used as identifiers. Here are the full ECMAScript keywords (with asterisks are new keywords in version 5) :

break do instanceof typeof case else new var catch finally return void continue for switch while debugger* function this  with default if throw delete in tryCopy the code

Ecma-262 also describes another set of reserved words that cannot be used as identifiers. Although reserved words do not yet have any specific purpose in the language, they may be used as keywords in the future. The following are all reserved words as defined by ECMA-262 version 3:

abstract enum int short boolean export interface static 
byte extends long super char final native synchronized 
class float package throws const goto private transient 
debugger implements protected volatile double import public 
Copy the code

Version 5 reduces the reserved words when running in non-strict mode to the following:

class enum extends super const export import
Copy the code

In strict mode, version 5 also imposes restrictions on the following reserved words:

implements package public interface private static let protected yield
Copy the code

variable

ECMAScript variables are loosely typed, meaning they can be used to hold any type of data. In other words, each variable is just a placeholder to hold the value. When defining variables, use the var operator (note that var is a keyword), followed by the variable name (that is, an identifier)

The data type

  1. Boolean  
  2. Null  
  3. Undefined 
  4. Number
  5. BigInt
  6. String
  7. Symbol
  8. Object

conclusion

The core language features of JavaScript are defined in ECMA-262 in the form of a pseudo-language called ECMAScript. ECMAScript contains all the basic syntax, operators, data types, and objects necessary to perform basic computational tasks, but does not specify the mechanism for taking input and producing output. Understanding ECMAScript and its intricacies is key to understanding its implementation in Web browsers, JavaScript. Most implementations currently follow ecMA-262 version 3, but many have started implementing version 5 as well. The following is a brief summary of the basic elements of ECMAScript.

  1. Basic data types in ECMAScript include Undefined, Null, Boolean, Number, and String.

  2. Unlike other languages, ECMScript does not define separate data types for integer and floating point values, and the Number type can be used to represent all values.

  3. ECMAScript also has a complex data type, the Object type, which is the base type for all objects in the language.

  4. Strict patterns impose limits on what can go wrong in the language.

  5. ECMAScript provides many of the same basic operators as C and other C-like languages, including arithmetic, Boolean, relational, equality, and assignment operators.

  6. ECMAScript borrows many flow-control statements from other languages, such as the if statement, the for statement, and the switch statement. Functions in ECMAScript differ in a number of ways from functions in other languages.

  7. There is no need to specify the return value of the function, because any ECMAScript function can return any value at any time.

  8. In fact, functions that do not specify a return value return a special undefined value.

  9. There is also no concept of function signatures in ECMAScript, because function arguments are passed as an array of zero or more values.

  10. Any number of arguments can be passed to an ECMAScript function and can be accessed via the Arguments object.

  11. ECMAScript functions cannot be overloaded because there is no function signature feature.

————————————————————————————————

Continuous serial ~~~