Gain Lifetime access of knowledge.

No More lagging behind being as a Tech Savvy?

education online books
What's inside?

Preview at glance

Introducing ebook

In this book you have for your computer is a common, well-understood one, such as showing you your email or acting like a calculator, you can open the appropriate application and get to work. But for unique or open-ended tasks, there often is no appropriate application.

This book will try to make you familiar enough with this language to do useful and amusing things with it.

That is where programming may come in. Programming is the act of constructing a program—a set of precise instructions telling a computer what to do. Because computers are dumb, pedantic beasts, programming is fundamentally tedious and frustrating.

Values, Types, and Operators

In the computer’s world, there is only data. You can read data, modify data, create new data—but that which isn’t data cannot be mentioned. All this data is stored as long sequences of bits and is thus fundamentally alike.

It is important to note that JavaScript has almost nothing to do with the programming language named Java. The similar name was inspired by marketing considerations rather than good judgment.

To be able to work with such quantities of bits without getting lost, we separate them into chunks that represent pieces of information. In a JavaScript environment, those chunks are called values. Though all values are made of bits, they play different roles. Every value has a type that determines its role. Some values are numbers, some values are pieces of text, some values are functions, and so on.

Program Structure

In this chapter, we will start to do things that can actually be called programming. We will expand our command of the JavaScript language beyond the nouns and sentence fragments we’ve seen so far to the point where we can express meaningful prose.

A fragment of code that produces a value is called an expression. Every value that is written literally (such as 22 or "psychoanalysis") is an expression. An expression between parentheses is also an expression, as is a binary operator applied to two expressions or a unary operator applied to one.

How does a program keep an internal state? How does it remember things? We have seen how to produce new values from old values, but this does not change the old values, and the new value must be used immediately or it will dissipate again. To catch and hold values, JavaScript provides a thing called a binding, or variable.

Functions

Functions are one of the most central tools in JavaScript programming. The concept of wrapping a piece of program in a value has many uses. It gives us a way to structure larger programs, to reduce repetition, to associate names with subprograms, and to isolate these subprograms from each other.

The most obvious application of functions is defining new vocabulary. Creating new words in prose is usually bad style, but in programming, it is indispensable.

A function definition is a regular binding where the value of the binding is a function. For example, this code defines square to refer to a function that produces the square of a given number

Parameters to a function behave like regular bindings, but their initial values are given by the caller of the function, not the code in the function itself.

Data Structures

Numbers, Booleans, and strings are the atoms from which data structures are built. Many types of information require more than one atom, though. Objects allow us to group values—including other objects—to build more complex structures.

The programs we have built so far have been limited by the fact that they were operating only on simple data types. After learning the basics of data structures in this chapter, you’ll know enough to start writing useful programs.

We’ve seen a few expressions like myString.length (to get the length of a string) and Math.max (the maximum function) in past chapters. These expressions access a property of some value. In the first case, we access the length property of the value in myString. In the second, we access the property named max in the Math object (which is a collection of mathematics-related constants and functions).

Learn

Online Learning Academy

Though the gravity still dragged at him, his muscles were making great efforts to adjust. After the daily classes he no longer collapsed.

What looked like a small patch of purple grass, above five feet square, was moving across the sand in their direction. When it came near enough he perceived that it was not grass there were no blades.

Reviews

What people saying...

Anita Developer
4.5

As someone completely new to coding, this JavaScript book made everything click! The explanations are clear, and the examples are easy to follow. I especially liked the exercises at the end of each chapter — they helped me build confidence step by step. Highly recommend for beginners!

Shekhar Team Head
3.5

This book goes beyond the basics and digs into ES6 features, async programming, and APIs, which I found very useful. It’s perfect for students who already know the fundamentals and want to level up their JavaScript skills. The projects at the end are a great way to apply what you learn.

Shreya VP, Design
5

We used this JavaScript book as part of our web development course, and it made learning much easier. The examples are modern and relevant, and the code snippets actually work! It’s also structured well for both self-study and classroom use.

Get your free ebook

Say hi and talk to us

Contact

United State

010-020-0340

info@company.com