Easy and tricky JavaScript core concepts for beginners

JavaScript is one of the most widely used programming languages in the world. It is a high-level, interpreted, and dynamically typed language that powers both frontend and backend development.

Because of its flexibility, JavaScript feels easy at first. However, as you go deeper, it reveals many tricky behaviors that often confuse beginners. Therefore, understanding its core concepts properly is very important.

In this guide, we will explore both easy and tricky JavaScript concepts in a clear and practical way.

What is JavaScript?

JavaScript is a scripting language used to make web pages interactive. For example, it helps in:

  • Form validation
  • Dynamic content updates
  • Web applications
  • Server-side development (Node.js)

Moreover, it works in almost every browser, which makes it extremely powerful.

JavaScript Data Types

JavaScript has two main categories of data types:

Primitive Data Types

These are basic types:

  • String → "hello"
  • Number → 10, 10.5
  • Boolean → true / false
  • Undefined → variable declared but not assigned
  • Null → empty value
  • Symbol → unique identifier
  • BigInt → large integers

Non-Primitive Data Type

  • Object → collection of key-value pairs

How to Check Data Type in JavaScript

To check the type of a variable, we use the typeof operator.

typeof 10;        // "number"
typeof "hello"; // "string"
typeof true; // "boolean"
typeof undefined; // "undefined"
typeof {}; // "object"

Special Case: null

typeof null; // "object"

This is a known JavaScript bug. Even though null means "empty value", its type is incorrectly shown as "object".

Difference Between == and ===

This is one of the most important concepts in JavaScript.

Loose Equality (==)

  • Compares only value
  • Performs type conversion
1 == "1"; // true

Strict Equality (===)

  • Compares value + type
1 === "1"; // false

Conclusion:

Always prefer === to avoid unexpected results.

NaN (Not a Number) – A Tricky Concept

NaN means “invalid number result”.

typeof NaN; // "number"

Strange Behavior:

NaN === NaN; // false

NaN is the only value in JavaScript that is not equal to itself.

Correct way to check NaN:

Number.isNaN(NaN); // true

Dynamic Typing in JavaScript

JavaScript is a dynamically typed language. This means variables can change type at runtime.

let a = 10;
typeof a; // "number"

a = "hello";
typeof a; // "string"

This flexibility is powerful but can also lead to bugs.

Strict Mode ("use strict")

Strict mode helps you write safer JavaScript code.

"use strict";

x = 10; // Error: x is not defined

Without strict mode:

x = 10; // Works but creates a global variable (bad practice)

Therefore, always use "use strict".

Scope in JavaScript

Scope defines where a variable can be accessed.

Global Scope

Accessible everywhere:

let a = 10;

Local Scope

Accessible only inside a function:

function test() {
let b = 20;
}

Important Behavior: Primitives vs Objects

Primitives (pass by value)

let a = 1;

function change(x) {
x = 2;
}

change(a);
console.log(a); // 1

Objects (reference behavior)

let obj = {};

function change(o) {
o.name = "JavaScript";
}

change(obj);
console.log(obj); // { name: "JavaScript" }

Objects are passed by reference, so changes affect original data.

isNaN vs Number.isNaN

isNaN (confusing behavior)

isNaN("a"); // true

Number.isNaN (recommended)

Number.isNaN("a"); // false

Always prefer Number.isNaN() for accurate results.

Conclusion

JavaScript is simple at the surface but contains many tricky behaviors under the hood. Once you understand these core concepts properly, you will become much more confident in writing real-world applications.

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Site Footer

Sliding Sidebar

We are India’s largest Startup Community


We are team of ' Delhi Startups ' , most active startup community with strict spam policy.
We are making !deas happen..for future, business and jobs without charging anything, with connecting entrepreneurs.. It's a reason to trust on us.
Come and join or subscribe, we will defiantly give a reason to like us.

Our Facebook Page