Password Strength Checker In jQuery In Hindi
Generator Functions In JavaScript In Hindi | JavaScript Generator Functions
async - await In JavaScript In Hindi | JS async - await In Hindi
JavaScript Object keys, values, entries : Object methods in JS
Nullish Coalescing Operator In JavaScript In Hindi
PHP ctype Functions | ctype Functions In PHP In Hindi
Difference Between SOAP AND REST API In Node - Express In Hindi
PHP Form validation | Validate User Input Data In PHP In Hindi
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Hello Learners ! अगर आप JavaScript use करते हैं तो अपने console.log()
method तो जरूर use किया होगा , लेकिन क्या आप जानते हैं console Object window Object की ही एक property है और log()
की तरह ही इसमें कई और methods भी हैं।
हालाँकि कई developers console Object को नजरअंदाज कर देते हैं , लेकिन कोई नहीं इस article में हम console Object और इसके useful methods के बारे में बात करेंगे।
Image on pixabay
JavaScript में console
object , window Object की ही एक property है। जो हमें browser के debugging console का access provide करता है जिसकी help से हम need के according console पर message , error या info write / clear कर सकें।
console object के सभी methods को access करने के लिए आप window.console
या सिर्फ console
use कर सकते हैं क्योंकि window Object तो globally available रहता ही है।
conosle
Object के कुछ useful methods इस प्रकार हैं -
log()
info()
error()
warn()
table()
group()
clear()
trace()
assert()
इस method की help से किसी message को console पर log (write) करने के लिए किया जाता है , बैसे किसी developer द्वारा इस methods को JavaScript में सबसे ज्यादा बार use किया जाता है।
let obj = {fname:"Rahul", ltname:"Rajput"};
console.log(obj);
console message देखने के लिए browser console open करना न भूले। browser console को right click करके inspect पर click करके या F12 press करके open कर सकते हैं।
info()
method की help से किसी message को console पर write करने के लिए किया जाता है , जब आप info() method use करते हो तो message के starting में एक i
icon देखने को मिलेगा , जो info को indicate करता है।
console.info("This is info message");
error() method का use console पर errors write करने के लिए किया जाता है , यह method testing purposes के लिए काफी useful है।
console.error("Oh ! no , you just did something wrong");
warn()
method का use console पर warning write करने के लिए किया जाता है । , जब आप warn() method use करते हो तो message के starting में एक warning icon देखने को मिलेगा।
console.warn("Do not run it again ...");
console.warn(["you", "can", "print", "anything"]);
ध्यान रहे , Browser में logs / errors या warning को enable करना पड़ेगा तभी आपको ये messages दिखेंगे।
debug करने के लिए ये भी एक अच्छा method है , table()
method का use console पर Array या Object को table की form में write करने के लिए किया जाता है ।
// print array.
console.table(["Raju", "Ram", "Rahul"]);
// print Object.
console.table({fname:"Rahul", lname : "Kumar", address:"UP, India"});
हालाँकि , table() method में अगर आप कोई string / number pass कर रहे हैं तो normal message की तरह ही print होगा।
इस method के name से आप समझ सकते हैं कि इसका use console clear करने के लिए किया जाता है ।
console.log("log");
console.info("info");
console.warn("warning");
console.error("error");
console.clear("Cleared");
अगर आपको किसी condition के according console message print कराना है , तो आप assert()
method का use कर सकते हैं। ये method argument accept करता है , पहला boolean value : true
| false
और दूसरा message . condition गलत होने पर message print होगा।
console.assert(false, "It will print definitely.");
//or
let x = 90, y = 20;
console.assert(x == y, "x, y are not equal.");
group()
method का use console पर messages की grouping करने के लिए किया जाता है। इस method को endGroup()
method के साथ use किया जाता है।
Messages की grouping करने के लिए हर group को एक name देना होता है , जिसे label कहते हैं। label
को आपको group()
में pass करना पड़ता है।
// group 1
console.group("Group 1");
console.log("message inside group 1");
console.log("another message inside group 1");
console.groupEnd();
// group 2
console.group("Group 2");
console.log("message inside group 2");
console.log("another message inside group 2");
console.groupEnd();
time()
method का use console view पर timer start करने के लिए किया जाता है। performance testing के हिसाब से काफी useful method है। इस method को endTime()
method के साथ use किया जाता है।
इस method को use करने के लिए time()
और endTime()
दोनों में same label pass करना पड़ता है।
Example के लिए नीचे example में यह check किया गया है कि for Loop और while Loop में कौन सा ज्यादा fast है -
console.time("for Loop");
for (let i = 0; i < 5000000; i++) ;
console.timeEnd("for Loop");
let i = 0;
console.time("while Loop");
while (i < 5000000) i++;
console.timeEnd("while Loop");
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook