-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JavaScript is a dynamically typed language, meaning variables are not bound to a specific data type. Sometimes JavaScript automatically converts values to another type (implicit conversion), and sometimes you must convert them manually (explicit conversion).
JavaScript automatically converts data types when performing operations involving different types.
let result = "5" + 2; // "52" → number 2 is converted to string
let value = "10" - 3; // 7 → string "10" is converted to number
📌 Rules:
+
operator with a string → converts everything to a string
Other arithmetic operators (-
, *
, /
) → convert strings to numbers (if possible)
You can manually convert one type to another using built-in functions:
Function | Converts to | Example | Result |
---|---|---|---|
String(value) |
String | String(123) |
"123" |
Number(value) |
Number | Number("456") |
456 |
Boolean(value) |
Boolean | Boolean(1) |
true |
let num = 100;
String(num); // "100"
num.toString(); // "100"
let str = "42";
Number(str); // 42
parseInt("42.5"); // 42
parseFloat("42.5"); // 42.5
Boolean(0); // false
Boolean(""); // false
Boolean("hello"); // true
Boolean(123); // true
0
""
(empty string)
null
undefined
NaN
false
Everything else is considered truthy.
Q1. How do you explicitly convert a number 123
to a string using String()
?
Q2. What is the result of "5" + 10
and why does it happen?
Q3. How do you convert the string "42"
to a number and store it in a variable num
?
Q4. How do you check the boolean value of a non-empty string like "hello"
?
Q5. What is the result of Boolean(0)
and what does it represent?
Q6. How do you convert the string "3.14"
to a float using parseFloat()
?
Q7. How do you use toString()
to convert a boolean true
to a string?
Q8. How do you convert the number 10
into a boolean?
Q9. What happens if you use Number("abc")
? What is the output?
Q10. How do you convert an empty string ""
to a boolean and what is the result?
Q1: What does String(100) return?
Q2: What is the result of "10" - 3?
Q3: Which of the following is a falsy value in JavaScript?
Q4: What does Boolean("0") return?
Q5: Which method will convert "3.14" to 3.14 as a number?
Q6: What will be the result of Number("abc")?
Q7: What will Boolean("") return?
Q8: Which of the following will result in string concatenation?
Q9: Which function converts any value to a string safely, even if it's null or undefined?
Q10: What is the type of result after parseInt("45.67")?