Assertion in javascript
In assertion,we have two arguments ,One is expectations statement and other is exact result we are trying to match ,its throws an exception,if expectations are not correct
1// Operators for booleans
2assert.equal(true && false, false); // And
3assert.equal(true || false, true); // Or
4// Operators for numbers
5assert.equal(3 + 4, 7);
6assert.equal(5 - 1, 4);
7assert.equal(3 * 4, 12);
8assert.equal(10 / 4, 2.5);
9// Operators for bigints
10assert.equal(3n + 4n, 7n);
11assert.equal(5n - 1n, 4n);
12assert.equal(3n * 4n, 12n);
13assert.equal(10n / 4n, 2n);
14// Operators for strings
15assert.equal('a' + 'b', 'ab');
16assert.equal('I see ' + 3 + ' humans', 'I see 3 humans');
17// Comparison operators
18assert.equal(3 < 4, true);
19assert.equal(3 <= 4, true);
20assert.equal('abc' === 'abc', true);
21assert.equal('abc' !== 'def', true);
Ordinary function declarations
1 // add1() has the parameters a and b
2function add1(a, b) {
3return a + b;
4}
5// Calling function add1()
6assert.equal(add1(5, 2), 7);
About
Moiz is a software engineer from Arid University with a passion for writing tech tutorials and doing coding. I am continously produce JavaScript and other web development technology tutorials in concepts through easy-to-understand explanations written in plain English.I have expertise in next js ,react js ,javascript,html,bootstrap and node js.
Follow him on TwitterHassan is a software engineer from kohat university of science and technology with a passion for writing tech tutorials and doing javascript practices on daily basis.I have expertise in next js ,react js ,javascript,html,bootstrap and node js. Problem Solving and making concpets is my strong point.
Follow him on TwitterTags
Click to see all tutorials tagged with: