#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
JavaScript Fundamentals

Language

Besides arithmetic, comparison and logical operators, JavaScript has a group of operators that work with the language itself rather than with numbers or booleans. They check a value's type, test object relationships, create and remove properties and objects, or combine expressions. The main ones are typeof, instanceof, in, delete, new, void, the comma operator and the conditional (ternary) operator.

typeof: what kind of value is this?

typeof returns a string describing a value's type. It is safe even on variables that were never declared, which makes it useful for feature checks.

typeof 42;            // "number"
typeof 'hi';          // "string"
typeof true;          // "boolean"
typeof undefined;     // "undefined"
typeof 10n;           // "bigint"
typeof Symbol('id');  // "symbol"
typeof {};            // "object"
typeof [];            // "object"  (arrays are objects)
typeof null;          // "object"  (a long-standing quirk)
typeof function () {}; // "function"

Because typeof null and typeof [] both give "object", use value === null and Array.isArray(value) when you need to tell them apart.

instanceof and in: relationships and keys

obj instanceof Ctor checks whether Ctor.prototype appears in the object's prototype chain. 'key' in obj checks whether a property exists on the object or anywhere up its prototype chain, even if its value is undefined.

class Shape {}
class Circle extends Shape {}
const c = new Circle();

c instanceof Circle;   // true
c instanceof Shape;    // true
[] instanceof Array;   // true

const settings = { theme: undefined };
'theme' in settings;      // true, the key exists
settings.theme !== undefined; // false, so this check misses it
'toString' in settings;   // true, inherited from Object.prototype

delete settings.theme;    // removes the property, returns true
'theme' in settings;      // false

const total = (1, 2, 3);  // comma operator: evaluates all, returns 3
const label = c instanceof Circle ? 'round' : 'other'; // conditional

delete, new and void

  • delete removes a property from an object. It does not free memory directly and cannot remove variables declared with let, const or var.
  • new calls a constructor or class to create a new object instance.
  • void evaluates an expression and returns undefined. You may see it in old links as href="javascript:void(0)"; a real <button> is the better choice today.

The ternary and comma operators

The conditional operator condition ? a : b is the only operator that takes three operands. It picks a value and is widely used in template literals and JSX. The comma operator evaluates expressions left to right and returns the last one. You mostly see it in for loops, such as for (let i = 0, j = 10; i < j; i++, j--). Elsewhere it tends to hurt readability.

Where these operators mislead you

Using delete on an array element is a common mistake. delete arr[1] leaves an empty hole and does not change length. Use arr.splice(1, 1) to actually remove an item, or filter to make a new array without it.

instanceof can fail across frames or windows, because each one has its own Array constructor. Array.isArray() works everywhere, so prefer it for arrays.

And remember that in includes inherited keys. To check only the object's own properties, use Object.hasOwn(obj, 'key').

Quick reference

OperatorReturns
typeof xA type name string
x instanceof CBoolean, based on the prototype chain
'k' in objBoolean, own or inherited key
delete obj.kBoolean; removes the property
void exprundefined
a ? b : cb or c

In practice, reach for typeof for primitives, Array.isArray for arrays, Object.hasOwn for own keys and splice rather than delete on arrays.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course