官术网_书友最值得收藏!

  • The JavaScript Workshop
  • Joseph Labrecque Jahred Love Daniel Rosenbaum Nick Turner Gaurav Mehla Alonzo L. Hosford Florian Sloot Philip Kirkbride
  • 492字
  • 2021-06-11 12:53:02

Introduction

In the previous chapter, you were given a tour of JavaScript, its runtimes, and its history. Using a high-level topography, that chapter will have given you an idea as to what JavaScript is, what it can do, and its ubiquity within the internet software development industry.

Understanding code can be difficult for beginners. JavaScript is no exception. Its flexibility, extensive language syntax, and varying coding patterns can prove daunting to the uninitiated.

This chapter will take you a step closer to writing your own software applications in JavaScript. By explaining the fundamentals, you will be empowered to not only understand what scripts do, but how to reason about problems using JavaScript syntax.

In this chapter, you will take a close look at JavaScript's type system. All programming languages have a type system. Types literally dictate the type of data stored in a variable or function parameter. Types are typically separated into two categories: primitive and complex types.

In JavaScript, all primitive data types are immutable. This means that the value cannot be changed in memory. New values can be assigned to a variable, but the underlying data stored in memory cannot be modified directly. This differs from the case in languages such as C++, where values can be directly altered in memory using pointers and helper functions. In JavaScript, when passing a primitive value from one variable to another, the data is copied in memory to the new variable. Therefore, updating one variable does not affect the other.

Complex data types work differently. They are also known as reference types. Reference types include the Object type and all of its derivatives, such as Array, Date, and Function. All reference types are passed by reference, hence the name. Therefore, if an object is modified through one reference, all the other references that share the same object will see it as updated too, since all of the references point to the same data in memory.

A complex type is simply a type that has more functionality than a primitive. For instance, a Date value provides additional means of representation, while objects can contain many nested values, such as primitives and other complex types.

Note

Function types will not be explained in detail in this chapter and will instead be covered in a later chapter when prototypes are introduced.

All primitives, and preexisting reference types are known as built-in data types. Each of these types has a corresponding object that provides functions for manipulating that type. These functions may be applied externally to data by passing the value as a parameter to a function, or they may be applied by calling the function as if it were a method of that type. The latter is also applicable to several primitives, despite them not existing as literal objects within the JavaScript type system. However, this is made possible through the syntactical context of the data. More will be explained about this feature throughout this chapter.

主站蜘蛛池模板: 柞水县| 同仁县| 当涂县| 嵊州市| 玛沁县| 英超| 綦江县| 兴和县| 余庆县| 连南| 社旗县| 高邑县| 莆田市| 吴江市| 巴塘县| 广西| 那曲县| 阜新| 镇沅| 宕昌县| 大名县| 和林格尔县| 措美县| 中方县| 上饶县| 新建县| 桃源县| 清丰县| 成都市| 修水县| 玛纳斯县| 丹棱县| 林口县| 鄂托克旗| 香港 | 垣曲县| 玉龙| 师宗县| 灯塔市| 东台市| 犍为县|