wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

JavaScript / Node.js Logic (Async, Scopes, Types)

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What’s the output? console.log('A'); setTimeout(()=>console.log('B'), 0); Promise.resolve().then(()=>console.log('C')); console.log('D');

a)

A. A B C D

b)

B. A D B C

c)

C. A C D B

d)

D. A D C B

2.

What prints? var x = 10; (function(){ console.log(x); var x = 20; console.log(x); })();

a)

A. 10, 20

b)

B. undefined, 20

c)

C. ReferenceError, 20

d)

D. 10, undefined

3.

What is [1,2,3].map(parseInt)?

a)

[1, 2, 3]

b)

[1, NaN, NaN]

c)

[NaN, NaN, NaN]

d)

Throws

4.
  1. What prints?

const obj = {a:1}; const arr=[obj];

obj.a=2; console.log(arr[0].a);

a)

1

b)

2

c)

undefined

d)

Error

5.

typeof null equals:

a)

"null"

b)

"object"

c)

"undefined"

6.

What’s true about requiring the same Node module twice?

a)

Loads twice, new instance each

b)

Uses a shared cached instance

c)

Loads fresh each event loop tick

d)

Only works once per process

7.

Execution order? console.log('start'); process.nextTick(()=>console.log('tick')); Promise.resolve().then(()=>console.log('promise')); setTimeout(()=>console.log('timeout'),0); console.log('end');

a)

A. start, end, promise, tick, timeout

b)

B. start, end, tick, promise, timeout

c)

C. start, tick, end, promise, timeout

d)

D. start, promise, end, tick, timeout

8.

What is typeof NaN?

a)

"nan"

b)

"number"

c)

"undefined"

d)

"object"

9.

Which is idempotent per HTTP spec?

a)

POST

b)

PATCH

c)

PUT

d)

CONNECT

10.

Which expression is true?

a)

[] == []

b)

{ } == { }

c)

[] == ![]

d)

null == 0

11.

What prints? for (var i=1;i<=3;i++){ setTimeout(()=>console.log(i),0); }

a)

A. 1 2 3

b)

B. 3 3 3

c)

C. 0 1 2

d)

D. 1 1 1

12.

12. Debounce vs Throttle:

a)

Debounce triggers at a fixed rate; throttle after idle

b)

Debounce waits for silence; throttle limits calls per interval

c)

Both do the same

d)

Debounce calls immediately and never again

13.

Two calls in one handler: const [count,setCount]=useState(0); setCount(count+1); setCount(count+1);

a)

+0

b)

+1

c)

+2

d)

Undefined behavior

14.

Using functional updates twice: setCount(c=>c+1); setCount(c=>c+1);

a)

+0

b)

+1

c)

+2

d)

+3

15.

useEffect(fn, []) runs:

a)

Before first render

b)

After first paint only

c)

Every render

d)

Only on unmount

16.

Effect cleanup runs:

a)

After render completes

b)

Before next effect run and on unmount

c)

Only on errors

d)

Never automatically

17.

useMemo vs useCallback:

a)

Both memoize values

b)

useMemo → value, useCallback → function

c)

useCallback → value, useMemo → function

d)

Neither memoizes

18.

Why are keys required in list items?

a)

For styling

b)

For SEO

c)

To keep stable identity/state across reorders

d)

To force re-renders

19.

Controlled input means:

a)

DOM manages value

b)

Value is derived from React state

c)

Input is read-only

d)

Uses refs

20.

In Next.js (pages router), server-side data fetch occurs in:

a)

getStaticProps at runtime per request

b)

getServerSideProps per request

c)

useEffect

d)

getInitialProps only in API routes

21.

Best way to protect a JWT in a browser app?

a)

LocalStorage

b)

SessionStorage

c)

HTTP-only, secure cookie

d)

Inline in HTML

22.

In Next.js, which is best for static marketing pages that rarely change?

a)

getServerSideProps

b)

Client fetch in useEffect

c)

getStaticProps (SSG)

d)

API route proxy on every hit

23.

Correct order to validate JWT in Express:

a)

Route → Controller → Auth middleware

b)

Auth middleware → Route handler

c)

Controller → DB → Auth

d)

Error handler → Auth → Route

24.

For invalid/expired credentials, return:

a)

400

b)

401

c)

403

d)

409

25.

For authenticated user lacking permission, return:

a)

400

b)

401

c)

403

d)

422

26.

CORS preflight uses:

a)

GET

b)

OPTIONS

c)

HEAD

d)

TRACE

27.

Best place to rate-limit an Express API:

a)

After route handler

b)

Global middleware early in pipeline

c)

In database layer

d)

On client

28.

Validation error for well-formed JSON but semantically invalid fields:

a)

200

b)

400

c)

422

d)

500

29.

Ensure unique emails across users efficiently:

a)

Check in code before insert

b)

Create a unique index on email

c)

Store in array

d)

Use $group on every insert

30.

Which stage aggregates per restaurant daily orders?

a)

$project

b)

$matchthen$group\$matchthen\$group

c)

$lookupthen$project\$lookupthen\$\operatorname{proj}ect

d)

$unwindthen$skip\$unwindthen\$skip

31.

Which improves pipeline performance most often?

a)

$group early

b)

$match as early as possible

c)

$sort early

d)

$project at end

32.

Embedding vs referencing: when to reference?

a)

Small, bounded subdocs read with parent

b)

Highly relational data reused across collections

c)

Data never reused

d)

Always embed

33.

Atomicity in MongoDB:

a)

Multi-document ops are atomic by default

b)

Single-document writes are atomic

c)

Reads are atomic, writes not

d)

Nothing is atomic

34.

Upsert with defaults during create:

a)

updateOne(query, {$set:doc}, {upsert:true})

b)

findOneAndUpdate(query, {$setOnInsert:doc}, {upsert:true})

c)

insert(doc) then update

d)

$merge

35.

Enforce uniqueness of franchiseEmail per ownerId:

a)

Unique index on franchiseEmail

b)

Compound unique index on {ownerId, franchiseEmail}

c)

TTL index

d)

Text index

36.

Populate in Mongoose is used to:

a)

Denormalize documents

b)

Join referenced docs by replacing ObjectIds with documents

c)

Create indexes

d)

Hash passwords

37.

Principle of least privilege in IAM means:

a)

Attach AdministratorAccess to be safe

b)

Grant only permissions required to perform tasks

c)

Use inline policies everywhere

d)

Prefer root user for automation

38.

S3 pre-signed URLs let you:

a)

Create buckets

b)

Upload/download objects temporarily without exposing AWS keys

c)

Launch EC2 instances

d)

Add bucket policies

39.

EC2 security group inbound rule controls:

a)

Outgoing traffic from instance

b)

Incoming traffic to instance

c)

S3 access only

d)

IAM permissions

40.

Safest way to store API secrets for a Node app on EC2:

a)

Hard-code in repo

b)

User-data script echo to file

c)

AWS Systems Manager Parameter Store / Secrets Manager

d)

Env vars in .env committed to Git

41.

Zero-downtime upgrade for a web API:

a)

SSH and restart process

b)

Stop instance then start

c)

Use Load Balancer with two targets and rolling deploy

d)

Kill process and PM2 will revive

42.

Best fit for static portfolio hosting + global CDN:

a)

S3 static website + CloudFront

b)

EC2 only

c)

RDS + EC2

d)

Lambda only

43.

git revert vs git reset --hard :

a)

Both rewrite history

b)

revert creates a new commit undoing changes; reset --hard moves HEAD and discards history

c)

Both are safe on shared branches

d)

reset --hard is safer for shared branches

44.

Purpose of package-lock.json:

a)

Speeds webpack

b)

Pins exact dependency versions for repeatable installs

c)

Lists scripts

d)

Stores env vars

45.

With ^1.2.3, NPM can install:

a)

1.2.x only

b)

1.x.x (≥1.2.3 <2.0.0)

c)

any version

d)

1.2.3 only

46.

Postman is primarily used to:

a)

Host APIs

b)

Design UIs

c)

Test and document APIs

d)

Manage Git

47.

Best status for successful POST creating a resource:

a)

200

b)

201

c)

202

d)

204

48.

ETags help with:

a)

Authentication

b)

Cache validation / conditional requests

c)

Encryption

d)

CORS

49.

Safest server-side password handling:

a)

Store plaintext

b)

Hash with bcrypt + salt

c)

Base64 encode

d)

MD5 without salt

50.

You need to speed up frequent GET /restaurants (rarely changing). Best first move:

a)

Add cache-control/ETag and a CDN/edge cache in front

b)

Switch to WebSockets

c)

Replace Express with bare Node

d)

Move to another regi