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

  • 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.

主站蜘蛛池模板: 新巴尔虎右旗| 黄冈市| 车致| 大城县| 舟曲县| 门源| 武隆县| 宁化县| 蚌埠市| 丰镇市| 隆回县| 佛山市| 安泽县| 两当县| 瑞金市| 广安市| 六安市| 铜川市| 闸北区| 射洪县| 霍林郭勒市| 宜川县| 崇文区| 诸城市| 遂溪县| 岑溪市| 新民市| 吉林市| 绥中县| 龙岩市| 通渭县| 盐津县| 固原市| 六盘水市| 噶尔县| 灵武市| 富川| 宣威市| 武平县| 九台市| 大理市|