You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A contract specifies the obligations and guarantees of the behavior from a function or expression at runtime. This acts as a set of rules that are expected from the input and output of a function or expression, and errors are generally reported whenever a contract is violated.
344
344
345
345
```js
346
-
// Define our contract : int -> int
346
+
// Define our contract : int -> boolean
347
347
constcontract= (input) => {
348
348
if (typeof input ==='number') returntrue
349
-
thrownewError('Contract violated: expected int -> int')
349
+
thrownewError('Contract violated: expected int -> boolean')
350
350
}
351
351
352
352
constaddOne= (num) =>contract(num) && num +1
353
353
354
354
addOne(2) // 3
355
-
addOne('some string') // Contract violated: expected int -> int
355
+
addOne('some string') // Contract violated: expected int -> boolean
0 commit comments