JavaScript for Testers
This page covers the part of JavaScript that a tester uses every day: values, functions, arrays, JSON, async code, and errors. It ends with a small script that you run with Node.js and change yourself.
6 min read6 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 16 sources16টি সোর্স · updated Nov 2026আপডেট: Nov 2026
await pauses, then continuesawait থামায়, তারপর এগোয়
Follow one async call: the promise is pending, then fulfilled or rejected. Then forget await and see what the test holds.একটা async কল অনুসরণ করুন: promise প্রথমে pending, তারপর fulfilled বা rejected। তারপর await বাদ দিন আর দেখুন টেস্টের হাতে কী থাকে।
You’ll learnআপনি শিখবেন
- An async function returns a promiseasync ফাংশন একটা promise ফেরত দেয়✓
- A promise starts pendingpromise শুরুতে pending থাকে
- What await waits forawait কীসের জন্য অপেক্ষা করে
- When catch and finally runcatch আর finally কখন চলে
- Why a missing await gives a promiseawait বাদ গেলে কেন promise মেলে
What it is
JavaScript is a lightweight interpreted (or just-in-time compiled) programming language with first-class functions Source 1সোর্স 1. It is best known as the language of web pages, but it also runs outside the browser, for example in Node.js Source 1সোর্স 1.
Node.js is an open-source, cross-platform JavaScript runtime. It runs V8, the JavaScript engine of Google Chrome, outside the browser Source 2সোর্স 2. Its standard library has asynchronous input and output, so code does not block while it waits Source 2সোর্স 2.
A tester meets JavaScript in the test tools. Postman tests are written in JavaScript Source 15সোর্স 15. Playwright tests are written in TypeScript or JavaScript Source 16সোর্স 16. The next pages build on this one: TypeScript for Testers, API Testing with Postman, and UI Automation with Playwright.
সহজ English
JavaScript is a lightweight programming language Source 1সোর্স 1. People know it from web pages, but it also runs outside the browser, for example in Node.js Source 1সোর্স 1.
Node.js runs JavaScript outside the browser, with the same engine that Google Chrome uses Source 2সোর্স 2. Its standard library does input and output asynchronously, so your code does not get stuck while it waits Source 2সোর্স 2.
A tester meets JavaScript in the test tools. You write Postman tests in JavaScript Source 15সোর্স 15, and Playwright tests in TypeScript or JavaScript Source 16সোর্স 16. The next pages build on this one: TypeScript for Testers, API Testing with Postman, and UI Automation with Playwright.
বাংলা ব্যাখ্যা
JavaScript হলো first-class function-সহ একটা হালকা, interpreted (বা just-in-time compiled) programming language Source 1সোর্স 1। এটা web page-এর language হিসেবে সবচেয়ে পরিচিত, কিন্তু browser-এর বাইরেও চলে, যেমন Node.js-এ Source 1সোর্স 1।
Node.js একটা open-source, cross-platform JavaScript runtime। এটা Google Chrome-এর JavaScript engine V8-কে browser-এর বাইরে চালায় Source 2সোর্স 2। এর standard library-তে asynchronous input/output আছে, তাই অপেক্ষার সময় কোড আটকে থাকে না Source 2সোর্স 2।
একজন টেস্টার টেস্ট টুলের ভেতরেই JavaScript পান। Postman-এর টেস্ট JavaScript-এ লেখা হয় Source 15সোর্স 15। Playwright-এর টেস্ট লেখা হয় TypeScript বা JavaScript-এ Source 16সোর্স 16। পরের পেজগুলো এই পেজের ওপর দাঁড়ানো: TypeScript for Testers, API Testing with Postman আর UI Automation with Playwright।
How it works
- Variables.
letdeclares a block-scoped variable Source 3সোর্স 3.constdeclares a block-scoped variable that cannot be re-assigned and must get its value at once Source 3সোর্স 3. - Types. The standard defines eight data types: seven primitives, such as strings, numbers, booleans,
null, andundefined, and objects Source 3সোর্স 3. - Functions. JavaScript has first-class functions Source 1সোর্স 1. An arrow function, such as
(user) => user.name, is a shorter way to write a function Source 5সোর্স 5. - Arrays.
filter()returns a new array with the items for which the callback returned true Source 6সোর্স 6.map()returns a new array of the callback's results Source 6সোর্স 6.find()returns the first item for which the callback returned true Source 6সোর্স 6. - JSON.
JSON.stringify()turns a JavaScript value into a JSON string Source 14সোর্স 14.JSON.parse()turns a JSON string back into a value Source 7সোর্স 7. - Async code. An
asyncfunction always returns a promise Source 8সোর্স 8.awaitsuspends the function until the promise is fulfilled or rejected Source 8সোর্স 8. You can useawaitonly inside anasyncfunction or at the top level of a module Source 9সোর্স 9. - Errors. In
try...catch, thetryblock runs first. If it throws an exception, thecatchblock runs Source 10সোর্স 10. Afinallyblock always runs before the statement ends Source 10সোর্স 10. - Modules. Modules share code with
importandexportstatements Source 12সোর্স 12. Node.js treats a file that ends in.mjsas an ES module Source 12সোর্স 12.
সহজ English
- Variables.
letmakes a variable that lives inside its block Source 3সোর্স 3.constmakes one that you cannot assign again, and you give it a value right away Source 3সোর্স 3. - Types. There are eight data types: simple ones like text, numbers, true or false,
null, andundefined, plus objects Source 3সোর্স 3. - Functions. Arrow functions like
(user) => user.nameare a short way to write a function Source 5সোর্স 5. - Arrays.
filter()keeps the items that pass a check.map()changes each item into something new.find()gives you the first item that passes. The first two give you a new array Source 6সোর্স 6. - JSON.
JSON.stringify()turns a value into JSON text Source 14সোর্স 14.JSON.parse()turns JSON text back into a value Source 7সোর্স 7. - Waiting. An
asyncfunction always gives back a promise Source 8সোর্স 8.awaitpauses until the promise is done Source 8সোর্স 8. You can useawaitonly in anasyncfunction or at the top of a module Source 9সোর্স 9. - Errors.
tryruns first. If it throws an error,catchruns Source 10সোর্স 10.finallyalways runs at the end Source 10সোর্স 10. - Modules. Files share code with
importandexportSource 12সোর্স 12. Node.js treats a.mjsfile as an ES module Source 12সোর্স 12.
বাংলা ব্যাখ্যা
- Variable।
letএকটা block-scoped variable তৈরি করে Source 3সোর্স 3।const-ও block-scoped variable তৈরি করে, কিন্তু সেটা আবার assign করা যায় না, আর শুরুতেই value দিতে হয় Source 3সোর্স 3। - Type। Standard-এ আটটা data type আছে: সাতটা primitive, যেমন string, number, boolean,
nullআরundefined, আর object Source 3সোর্স 3। - Function। JavaScript-এ function first-class Source 1সোর্স 1।
(user) => user.name-এর মতো arrow function হলো function লেখার একটা ছোট উপায় Source 5সোর্স 5। - Array।
filter()একটা নতুন array দেয়, যেখানে থাকে শুধু সেই item-গুলো, যেগুলোর জন্য callback true দিয়েছে Source 6সোর্স 6।map()callback-এর ফলাফল দিয়ে নতুন array দেয় Source 6সোর্স 6।find()দেয় প্রথম item, যেটার জন্য callback true দিয়েছে Source 6সোর্স 6। - JSON।
JSON.stringify()একটা JavaScript value-কে JSON string বানায় Source 14সোর্স 14।JSON.parse()JSON string-কে আবার value বানায় Source 7সোর্স 7। - Async কোড।
asyncfunction সবসময় একটা promise ফেরত দেয় Source 8সোর্স 8। Promise fulfilled বা rejected না হওয়া পর্যন্তawaitfunction-টা থামিয়ে রাখে Source 8সোর্স 8।awaitশুধুasyncfunction-এর ভেতরে বা module-এর top level-এ ব্যবহার করা যায় Source 9সোর্স 9। - Error।
try...catch-এ আগেtryblock চলে। সেখানে exception হলেcatchblock চলে Source 10সোর্স 10।finallyblock সবসময় শেষে চলে Source 10সোর্স 10। - Module। Module
importআরexportদিয়ে কোড ভাগ করে Source 12সোর্স 12। Node.js.mjs-এ শেষ হওয়া file-কে ES module হিসেবে ধরে Source 12সোর্স 12।
Try it
You need Node.js. Save this as users.mjs and run node users.mjs. The .mjs extension makes the file an ES module Source 12সোর্স 12, so await works at its top level Source 9সোর্স 9. Node.js has a browser-compatible fetch() Source 13সোর্স 13, which the script uses to call the Postman Echo service.
const users = [
{ name: 'Asha', role: 'tester', active: true },
{ name: 'Rafi', role: 'developer', active: true },
{ name: 'Mina', role: 'tester', active: false },
];
const activeTesters = users
.filter((user) => user.active && user.role === 'tester')
.map((user) => user.name);
console.log(activeTesters); // [ 'Asha' ]
const firstDeveloper = users.find((user) => user.role === 'developer');
console.log(firstDeveloper.name); // Rafi
const text = JSON.stringify({ course: 'sdet', step: 3 });
console.log(JSON.parse(text).step === 3); // true
async function getEcho(course) {
try {
const response = await fetch(`https://postman-echo.com/get?course=${course}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const body = await response.json();
return body.args.course;
} catch (error) {
console.error('Request failed:', error.message);
throw error;
}
}
console.log(await getEcho('sdet')); // sdetThe output:
[ 'Asha' ]
Rafi
true
sdetNow change Mina to active: true and run it again. The first line becomes [ 'Asha', 'Mina' ]. Predict the output before each run: it is a quick way to learn the array methods.
সহজ English
You need Node.js. Save this as users.mjs and run node users.mjs. The .mjs ending makes it an ES module Source 12সোর্স 12, so await works at the top Source 9সোর্স 9. Node.js has a fetch() that works like the browser's Source 13সোর্স 13, and the script uses it to call Postman Echo.
const users = [
{ name: 'Asha', role: 'tester', active: true },
{ name: 'Rafi', role: 'developer', active: true },
{ name: 'Mina', role: 'tester', active: false },
];
const activeTesters = users
.filter((user) => user.active && user.role === 'tester')
.map((user) => user.name);
console.log(activeTesters); // [ 'Asha' ]
const firstDeveloper = users.find((user) => user.role === 'developer');
console.log(firstDeveloper.name); // Rafi
const text = JSON.stringify({ course: 'sdet', step: 3 });
console.log(JSON.parse(text).step === 3); // true
async function getEcho(course) {
try {
const response = await fetch(`https://postman-echo.com/get?course=${course}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const body = await response.json();
return body.args.course;
} catch (error) {
console.error('Request failed:', error.message);
throw error;
}
}
console.log(await getEcho('sdet')); // sdetIt prints [ 'Asha' ], Rafi, true, and sdet. Now set Mina to active: true and run it again. The first line becomes [ 'Asha', 'Mina' ]. Guess the output before each run: it is a quick way to learn the array methods.
বাংলা ব্যাখ্যা
আপনার Node.js লাগবে। এটা users.mjs নামে সেভ করে node users.mjs চালান। .mjs extension file-টাকে ES module বানায় Source 12সোর্স 12, তাই এর top level-এ await কাজ করে Source 9সোর্স 9। Node.js-এ browser-এর মতো একটা fetch() আছে Source 13সোর্স 13, script-টা সেটা দিয়ে Postman Echo service-কে call করে।
const users = [
{ name: 'Asha', role: 'tester', active: true },
{ name: 'Rafi', role: 'developer', active: true },
{ name: 'Mina', role: 'tester', active: false },
];
const activeTesters = users
.filter((user) => user.active && user.role === 'tester')
.map((user) => user.name);
console.log(activeTesters); // [ 'Asha' ]
const firstDeveloper = users.find((user) => user.role === 'developer');
console.log(firstDeveloper.name); // Rafi
const text = JSON.stringify({ course: 'sdet', step: 3 });
console.log(JSON.parse(text).step === 3); // true
async function getEcho(course) {
try {
const response = await fetch(`https://postman-echo.com/get?course=${course}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const body = await response.json();
return body.args.course;
} catch (error) {
console.error('Request failed:', error.message);
throw error;
}
}
console.log(await getEcho('sdet')); // sdetOutput হবে [ 'Asha' ], Rafi, true আর sdet। এবার Mina-কে active: true করে আবার চালান। প্রথম লাইন হবে [ 'Asha', 'Mina' ]। প্রতিবার চালানোর আগে output কী হবে আন্দাজ করুন: array method শেখার এটা একটা দ্রুত উপায়।
How a tester uses it
- Test data.
filter()keeps the items that pass a check,map()turns each item into a new value, andfind()returns the first item that passes Source 6সোর্স 6. Use them to pick the records that a test needs from a larger list. - API responses.
JSON.parse()turns a JSON string into a value Source 7সোর্স 7. Parse the body of a response, then check its fields.JSON.stringify()turns a value into a JSON string Source 14সোর্স 14: use it to build a JSON request body. - Waiting for results.
awaitwaits for a promise and returns its fulfilled value Source 9সোর্স 9. Use it before a call that returns a promise when the test needs that value. - Failures with context. Catch an error to log what the test was doing, then throw it again. The
catchblock runs only when thetryblock throws Source 10সোর্স 10. - Shared helpers. Put a helper, such as a login or a data builder, in a module, and
importit in each test Source 12সোর্স 12. - Exact checks. Compare with
===, which treats values of different types as different Source 11সোর্স 11.
সহজ English
- Test data.
filter()keeps what passes,map()changes each item, andfind()gives the first match Source 6সোর্স 6. Use them to pick the records a test needs. - API answers.
JSON.parse()turns JSON text into a value Source 7সোর্স 7. Parse the body, then check its fields.JSON.stringify()turns a value into JSON text Source 14সোর্স 14, for a request body. - Waiting.
awaitwaits for a promise and gives you its value Source 9সোর্স 9. Use it when the test needs the value of a call that returns a promise. - Errors that explain. Catch an error, write down what the test was doing, then throw it again.
catchruns only whentrythrows Source 10সোর্স 10. - Shared helpers. Put a helper in a module and
importit in each test Source 12সোর্স 12. - Exact checks. Use
===. It treats values of different types as different Source 11সোর্স 11.
বাংলা ব্যাখ্যা
- টেস্ট ডেটা।
filter()চেকে পাস করা item রাখে,map()প্রতিটা item-কে নতুন value বানায়, আরfind()প্রথম পাস করা item ফেরত দেয় Source 6সোর্স 6। বড় একটা list থেকে টেস্টের দরকারি record বেছে নিতে এগুলো ব্যবহার করুন। - API response।
JSON.parse()একটা JSON string-কে value বানায় Source 7সোর্স 7। Response-এর body parse করে তারপর তার field চেক করুন।JSON.stringify()একটা value-কে JSON string বানায় Source 14সোর্স 14: JSON request body বানাতে এটা ব্যবহার করুন। - ফলাফলের জন্য অপেক্ষা।
awaitএকটা promise-এর জন্য অপেক্ষা করে আর তার fulfilled value দেয় Source 9সোর্স 9। Promise ফেরত দেয় এমন call-এর value টেস্টের দরকার হলে তার আগে এটা দিন। - কারণসহ failure। Error catch করে টেস্ট তখন কী করছিল তা লিখে রাখুন, তারপর error-টা আবার throw করুন।
tryblock throw করলে তবেইcatchblock চলে Source 10সোর্স 10। - ভাগ করা helper। Login বা data builder-এর মতো helper একটা module-এ রাখুন, আর প্রতিটা টেস্টে
importকরুন Source 12সোর্স 12। - নির্ভুল চেক।
===দিয়ে তুলনা করুন, এটা আলাদা type-এর value-কে আলাদা ধরে Source 11সোর্স 11।
Common mistakes
==in a check. Strict equality treats values of different types as different, so"1" === 1isfalseSource 11সোর্স 11. Use===.- A missing
await. Anasyncfunction always returns a promise Source 8সোর্স 8. To get its fulfilled value,awaitthe promise Source 9সোর্স 9. - Trusting
consttoo much.constmakes the reference fixed, not the value, so the properties of an object in aconstcan still be added, updated, or removed Source 4সোর্স 4. - Parsing text that is not JSON.
JSON.parse()throws aSyntaxErrorwhen the text is not valid JSON Source 7সোর্স 7. Check the status of a response before you parse its body. - An empty
catch. When thetryblock throws, thecatchblock runs instead Source 10সোর্স 10. Put code there that reports the error, or throw it again.
সহজ English
==in a check.===treats different types as different, so"1" === 1isfalseSource 11সোর্স 11. Use===.- A missing
await. Anasyncfunction always gives back a promise Source 8সোর্স 8. To get its value,awaitit Source 9সোর্স 9. - Trusting
consttoo much.constfixes the reference, not the value, so an object in aconstcan still get properties added, updated, or removed Source 4সোর্স 4. - Parsing text that is not JSON.
JSON.parse()throws aSyntaxErrorif the text is not JSON Source 7সোর্স 7. Check the status before you read the body. - An empty
catch. Whentrythrows,catchruns instead Source 10সোর্স 10. Put code there that reports the error, or throw it again.
বাংলা ব্যাখ্যা
- চেকে
==ব্যবহার করা। Strict equality আলাদা type-এর value-কে আলাদা ধরে, তাই"1" === 1হলোfalseSource 11সোর্স 11।===ব্যবহার করুন। awaitবাদ পড়া।asyncfunction সবসময় একটা promise ফেরত দেয় Source 8সোর্স 8। এর fulfilled value পেতে promise-টাawaitকরুন Source 9সোর্স 9।const-এর ওপর বেশি ভরসা।constreference-টা স্থির করে, value-টা নয়, তাইconst-এ রাখা object-এর property তবুও যোগ, বদল বা মুছে ফেলা যায় Source 4সোর্স 4।- JSON নয় এমন text parse করা। Text ঠিক JSON না হলে
JSON.parse()একটাSyntaxErrorthrow করে Source 7সোর্স 7। Body parse করার আগে response-এর status দেখুন। - খালি
catch।tryblock throw করলে তার বদলেcatchblock চলে Source 10সোর্স 10। সেখানে error-এর খবর দেওয়ার কোড রাখুন, বা error-টা আবার throw করুন।
What a tester can check
Tutorial advice
This list is the tutorial's own advice, not a fact from a source.
- Comparisons. Do the checks use
===or the assertions of the test tool, never==? - Awaits. Is every async call awaited? Look for a call to an async helper with no
awaitin front. - Catch blocks. Does every
catchlog the context and throw again, or fail the test? - Test data. Is the data built from one source with
filter()andmap(), or copied by hand into many tests? - Helpers. Do the tests
importshared helpers, or does each test paste its own copy? - Secrets. Do the scripts read tokens and passwords from the environment, not from the code?
সহজ English
Tutorial advice
This list is the tutorial's own advice, not a fact from a source.
- Comparisons. Do the checks use
===or the tool's own assertions, never==? - Awaits. Is every async call awaited?
- Catch blocks. Does every
catchsay what happened and throw again, or fail the test? - Test data. Is the data built from one place, or copied by hand into many tests?
- Helpers. Do the tests share helpers with
import, or paste copies? - Secrets. Are tokens and passwords kept out of the code?
বাংলা ব্যাখ্যা
Tutorial advice
এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, কোনো source থেকে নেওয়া তথ্য নয়।
- তুলনা। চেকগুলো কি
===বা টেস্ট টুলের নিজের assertion ব্যবহার করে, কখনো==নয়? - Await। প্রতিটা async call কি await করা? সামনে
awaitছাড়া কোনো async helper-এর call খুঁজুন। - Catch block। প্রতিটা
catchকি কী হচ্ছিল তা লিখে error আবার throw করে, বা টেস্টকে fail করায়? - টেস্ট ডেটা। ডেটা কি এক জায়গা থেকে
filter()আরmap()দিয়ে তৈরি, নাকি অনেক টেস্টে হাতে কপি করা? - Helper। টেস্টগুলো কি shared helper
importকরে, নাকি প্রতিটা টেস্ট নিজের কপি বসায়? - Secret। Script কি token আর password environment থেকে পড়ে, কোড থেকে নয়?
Key words
| Term | Meaning |
|---|---|
let / const | Block-scoped variables; a const cannot be re-assigned, but its object can still change. |
| Primitive | One of the seven simple data types, such as a string, a number, or a boolean. |
| Arrow function | A short way to write a function: (user) => user.name. |
filter() / map() / find() | Array methods: keep the items that pass, transform each item, return the first item that passes. |
| JSON | Text for data. JSON.stringify() writes it and JSON.parse() reads it. |
| Promise | The value that an async function returns. |
await | Waits for a promise and returns its fulfilled value. |
try...catch | Runs the catch block when the try block throws. |
Strict equality (===) | A comparison that treats values of different types as different. |
| ES module | A file that shares code with import and export, such as a .mjs file in Node.js. |
| Node.js | The runtime that runs JavaScript outside the browser. |