Tuesday, June 10, 2025
The Script Diary
Advertisement
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
    • Home – Layout 6
  • News
    • All
    • Business
    • Politics
    • Science
    • World

    Hillary Clinton in white pantsuit for Trump inauguration

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Shooting More than 40 Years of New York’s Halloween Parade

    These Are the 5 Big Tech Stories to Watch in 2017

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Tech
    • All
    • Apps
    • Gadget
    • Mobile
    • Startup

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    These Are the 5 Big Tech Stories to Watch in 2017

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    • All
    • Gaming
    • Movie
    • Music
    • Sports

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    So you want to be a startup investor? Here are things you should know

  • Lifestyle
    • All
    • Fashion
    • Food
    • Health
    • Travel

    Shooting More than 40 Years of New York’s Halloween Parade

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    How couples can solve lighting disagreements for good

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Review

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    Intel Core i7-7700K ‘Kaby Lake’ review

No Result
View All Result
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
    • Home – Layout 6
  • News
    • All
    • Business
    • Politics
    • Science
    • World

    Hillary Clinton in white pantsuit for Trump inauguration

    Amazon has 143 billion reasons to keep adding more perks to Prime

    Shooting More than 40 Years of New York’s Halloween Parade

    These Are the 5 Big Tech Stories to Watch in 2017

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Tech
    • All
    • Apps
    • Gadget
    • Mobile
    • Startup

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    These Are the 5 Big Tech Stories to Watch in 2017

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    • All
    • Gaming
    • Movie
    • Music
    • Sports

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Harnessing the power of VR with Power Rangers and Snapdragon 835

    So you want to be a startup investor? Here are things you should know

  • Lifestyle
    • All
    • Fashion
    • Food
    • Health
    • Travel

    Shooting More than 40 Years of New York’s Halloween Parade

    Heroes of the Storm Global Championship 2017 starts tomorrow, here’s what you need to know

    Why Millennials Need to Save Twice as Much as Boomers Did

    Doctors take inspiration from online dating to build organ transplant AI

    How couples can solve lighting disagreements for good

    Ducati launch: Lorenzo and Dovizioso’s Desmosedici

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Review

    The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

    Shadow Tactics: Blades of the Shogun Review

    macOS Sierra review: Mac users get a modest update this year

    Hands on: Samsung Galaxy A5 2017 review

    The Last Guardian Playstation 4 Game review

    Intel Core i7-7700K ‘Kaby Lake’ review

No Result
View All Result
The Script Diary
No Result
View All Result
Home Uncategorized

JavaScript Interview Question

MD Khairuzzaman Rakib by MD Khairuzzaman Rakib
October 3, 2024
in Uncategorized
0
JavaScript Interview Question
0
SHARES
345
VIEWS
Share on FacebookShare on Twitter

1. Question 1:- Why do we call JavaScript as dynamic language?

JavaScript is referred to as a dynamic language because it allows for dynamic typing. This means that the same variable can be used to hold different data types. For instance, we can assign a number to a variable and then later assign a string to the same variable. Here’s an example:

var dynamicVariable = 5; // Number
console.log(dynamicVariable); // Output: 5

dynamicVariable = "Hello, World!"; // String
console.log(dynamicVariable); // Output: Hello, World!

In this example, the variable dynamicVariable first holds a number, then is reassigned to hold a string. This flexibility is part of what makes JavaScript a dynamic language.

JavaScript determines data types automatically when a variable is declared and assigned a value. Data types are distinguished between primitive types and object types. Primitive types in JavaScript include Number, String, Boolean, Undefined, Null, and Symbol. If a variable is not one of these types, it is considered an object. Here’s an example:

let num = 25; // Number
let str = "Hello"; // String
let bool = true; // Boolean
let nothing = undefined; // Undefined
let empty = null; // Null
let sym = Symbol("sym"); // Symbol

let obj = {name: "John"}; // Object

console.log(typeof num); // Output: number
console.log(typeof str); // Output: string
console.log(typeof bool); // Output: boolean
console.log(typeof nothing); // Output: undefined
console.log(typeof empty); // Output: object (null is considered an object in JavaScript)
console.log(typeof sym); // Output: symbol
console.log(typeof obj); // Output: object

In JavaScript, typeof is an operator that returns a string indicating the type of the unevaluated operand, i.e., the type of the data (not the variable itself). When used with a function, typeof returns the string “function”. Here’s an example:

function greet() {
  return "Hello, World!";
}

console.log(typeof greet); // Output: function

In this example, typeof is used with the function greet, and it returns the string “function”, indicating that the type of greet is a function.

In JavaScript, you can check the data type of a variable using the typeof operator. This operator returns a string indicating the type of the unevaluated operand. Here’s an example:

let num = 25; // Number
let str = "Hello"; // String
let bool = true; // Boolean

console.log(typeof num); // Output: number
console.log(typeof str); // Output: string
console.log(typeof bool); // Output: boolean

In this example, typeof is used to check the data type of the variables num, str, and bool.

JavaScript has seven fundamental data types:

  1. Number: Any numerical value, including decimals and negatives. For example, let num = 25;
  2. String: A sequence of characters enclosed in quotation marks. For example, let str = "Hello";
  3. Boolean: Represents either true or false. For example, let bool = true;
  4. Undefined: A variable that has been declared but has not yet been assigned a value is undefined. For example, let nothing;
  5. Null: Represents the intentional absence of any object value. For example, let empty = null;
  6. Symbol: A unique and immutable data type that is often used as an identifier for object properties. For example, let sym = Symbol("sym");
  7. Object: Anything that is not a primitive type (Number, String, Boolean, Null, Undefined, Symbol) is an object. For example, let obj = {name: "John"};

In JavaScript, undefined is a primitive data type. A variable that has been declared but not assigned a value is of type undefined. This is different from a variable not being declared at all, which will result in an error if you try to access it. Here’s an example:

let notAssigned;
console.log(notAssigned); // Output: undefined
console.log(typeof notAssigned); // Output: undefined

console.log(notDeclared); // Output: Error: notDeclared is not defined

In the first part of the example, notAssigned is declared but not assigned a value, so its value is undefined and its type is undefined. In the second part, notDeclared is not declared at all, so trying to access it results in an error.

In JavaScript, null is a primitive data type that represents the intentional absence of any object value. It is often used when you want to explicitly make a variable empty. Here’s an example:

let empty = null;
console.log(empty); // Output: null
console.log(typeof empty); // Output: object (interesting fact: null is considered an object in JavaScript)

When you declare a variable without using the var keyword, it becomes a global variable, regardless of where it was declared. This is because JavaScript treats it as if it was declared at the top-most scope. Here’s an example:

function exampleFunction() {
  noVar = "I'm a global variable!";
}

exampleFunction();
console.log(noVar); // Output: I'm a global variable!

In this example, noVar is declared inside exampleFunction without the var keyword. Despite this, it can be accessed outside the function because it’s treated as a global variable.

However, using variables without declaring them is considered a bad practice because it can lead to unexpected results and hard-to-debug code. Also, in strict mode ("use strict";), assigning a value to an undeclared variable, a read-only property, or a non-writable global variable, will throw an error.

Previous
Next Question 2:- how does JavaScript determine data types ?
Tags: interviewinterviewquestionJavascriptjavascriptquestion
Next Post

Game of Thrones spending just as long making fewer episodes

MD Khairuzzaman Rakib

MD Khairuzzaman Rakib

Next Post

Game of Thrones spending just as long making fewer episodes

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected test

  • 23.9k Followers
  • 99 Subscribers
  • Trending
  • Comments
  • Latest
JavaScript Interview Question

JavaScript Interview Question

October 3, 2024
What is Use Strict?

What is Use Strict?

October 11, 2024

Shadow Tactics: Blades of the Shogun Review

November 23, 2024

Why Millennials Need to Save Twice as Much as Boomers Did

November 14, 2024
JavaScript Interview Question

JavaScript Interview Question

0
What is Use Strict?

What is Use Strict?

0

The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

0

Shadow Tactics: Blades of the Shogun Review

0

The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

November 24, 2024

Shadow Tactics: Blades of the Shogun Review

November 23, 2024

macOS Sierra review: Mac users get a modest update this year

November 22, 2024

Hands on: Samsung Galaxy A5 2017 review

November 21, 2024

Recent News

The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

Shadow Tactics: Blades of the Shogun Review

macOS Sierra review: Mac users get a modest update this year

Hands on: Samsung Galaxy A5 2017 review

The Script Diary

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Follow Us

Browse by Category

  • Apps
  • Business
  • Entertainment
  • Fashion
  • Food
  • Gadget
  • Gaming
  • Health
  • Lifestyle
  • Mobile
  • Movie
  • Music
  • News
  • Politics
  • Review
  • Science
  • Sports
  • Startup
  • Tech
  • Travel
  • Uncategorized
  • World

Recent News

The Legend of Zelda: Breath of the Wild gameplay on the Nintendo Switch

November 24, 2024

Shadow Tactics: Blades of the Shogun Review

November 23, 2024
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.