Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Assertions

An assertion is a condition that must be tested to confirm that a certain piece of code behaves as expected, or, in other words, to confirm conformance to a requirement.

Let's imagine that we are working as part of the Google Chrome development team, and we must implement the JavaScript Math API. If we are working on the pow method, the requirement could be something like, the Math.pow (base, exponent) function should return the base (the base number) to the exponent (the exponent used to raise the base) power-that is, base ^ exponent.

With this information, we could create the following implementation:

class MathAPI { public static pow(base: number, exponent: number) { let result = base; for (var i = 1; i < exponent; i++) { result ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content