Contents
Introduction
Javascript में String, Number, Boolean, Undefined, Null जैसे primary data type है वह एक basic data structure है जो single value को hold करते है!. और ये value एक बार created होने के बाद में changed नहीं किया जा सकता है!. लेकिन javascript ऐसे कई method provides करता है जो value पर काम कर सकते है और value को change किये बिना value लोटा सकते है!.
सामन्य तोर पर primitive data type के लिए इस्तेमाल होने वाले method जैसे की:
Number methods:
toString():
toString(): यह method number को string में converts करती है!. और resulting string का इस्तेमाल
concatenation और other string operations में किया जा सकता है!.
Example:
let num = 123; let str = num.toString(); console.log(str); // "123"
toFixed():
toFixed(): यह method एक number को specified decimal number तक show करती है!.
और resulting string specified decimal number के साथ number को represents करती है!.
Example:
let num = 123.456; let fixedNum = num.toFixed(2); console.log(fixedNum); // "123.46"
toExponential():
toExponential(): यह method number को exponential notation string में converts करती है!.
और decimal number एक specified के रूप में निर्देश की जा सकती है!.
Example:
let num = 12345; let exponentialNum = num.toExponential(2); console.log(exponentialNum); // "1.23e+4"
toPrecision():
toPrecision(): यह method एक number को निर्दिष्ट महत्वपूर्ण आंकड़ों की संख्या तक rounds-up करती है।
Example:
let num = 123.456; let precisionNum = num.toPrecision(4); console.log(precisionNum); // "123.5"
String methods:
length:
length: ये property string के characters का number लोटती है!.
Example:
let str = "Hello, World!"; console.log(str.length); // 13
toUpperCase():
toUpperCase(): यह method string को uppercase में converts करती है!.
Example:
let str = "Hello, World!"; let upperCaseStr = str.toUpperCase(); console.log(upperCaseStr); // "HELLO, WORLD!"
toLowerCase():
toLowerCase(): यह method string को lowercase में converts करती है!.
Example:
let str = "Hello, World!"; let lowerCaseStr = str.toLowerCase(); console.log(lowerCaseStr); // "hello, world!"
indexOf():
indexOf(): यह method एक string में specified substring find करती है और यदि substring string में find होती है तो वह 1 लौटाती है और substring string में find नहीं होती है तो वह -1 लौटाती है!.
Example:
let str = "Hello, World!"; let index = str.indexOf("World"); console.log(index); // 7
substring():
substring(): यह method string का एक portion लौटाती है!. portion starting और ending indexing से specified किया जा सकता है!.
Example:
let str = "Hello, World!"; let subStr = str.substring(7, 12); console.log(subStr); // "World"