Welcome to Chapter 3: The Modern Mode - "use strict". In this chapter, we will learn about JavaScript's strict mode, why it is important, and how it helps us write safer and cleaner code.
By the end of this chapter, you will:
- Understand what "use strict" is.
- Learn how to enable strict mode.
- Identify the errors that strict mode prevents.
- Write safer JavaScript code with strict mode.
JavaScript strict mode is a way to enforce stricter parsing and error handling in your code. It helps avoid common coding mistakes and makes debugging easier.
Strict mode is enabled by adding "use strict" at the beginning of a script.
"use strict";
let name = "John";
alert(name);
"use strict";
let age = 25;
alert(age);
Strict mode helps in:
-
Preventing accidental global variables
"use strict"; let x = 10; alert(x);
-
Catching silent errors
"use strict"; let y = "Hello"; alert(y);
- Enable strict mode in a JavaScript program and test it using
alert
. - Write a program where strict mode prevents accidental global variables and display values using
alert
. - Create a script that shows the difference between strict mode and non-strict mode using
alert
. - Write a JavaScript script using
let
andalert
to demonstrate strict mode errors. - Use strict mode and
alert
to show how it prevents undeclared variables.
- Strict mode helps catch errors and enforce better coding practices.
- It prevents accidental global variables and catches silent errors.
- It makes debugging easier and improves JavaScript performance.
This chapter is presented by Muhammad Raza (SMRIT - Smart Modern Revolutionary IT Training). 🚀
خوش آمدید باب 3: جدید موڈ - "use strict"۔ اس باب میں ہم سیکھیں گے کہ strict mode کیا ہے، یہ کیوں ضروری ہے، اور یہ کوڈنگ کو کیسے بہتر بناتا ہے۔
جاوا اسکرپٹ کا strict mode کوڈ کو زیادہ محفوظ اور غلطیوں سے پاک بنانے میں مدد کرتا ہے۔
اسے فعال کرنے کے لیے اسکرپٹ کے آغاز میں "use strict" لکھا جاتا ہے۔
"use strict";
let name = "Ali";
alert(name);
"use strict";
let age = 30;
alert(age);
-
غلطی سے گلوبل ویری ایبل بننے سے بچاؤ
"use strict"; let x = 10; alert(x);
-
چھپی ہوئی غلطیوں کو پکڑتا ہے
"use strict"; let y = "Hello"; alert(y);
- strict mode کو جاوا اسکرپٹ میں فعال کریں اور
alert
کے ذریعے ٹیسٹ کریں۔ - ایسا پروگرام لکھیں جہاں strict mode غلطی سے گلوبل ویری ایبل بننے سے روکے اور
alert
کا استعمال کریں۔ - ایک ایسا اسکرپٹ لکھیں جو strict mode اور non-strict mode کے فرق کو ظاہر کرے اور
alert
استعمال کرے۔ - ایک ایسا جاوا اسکرپٹ اسکرپٹ لکھیں جہاں
let
اورalert
کا استعمال کرتے ہوئے strict mode کی غلطیوں کو دکھایا جائے۔ use strict
کا استعمال کرتے ہوئےalert
کے ذریعے ثابت کریں کہ یہ غیر اعلان شدہ ویری ایبلز کو کیسے روکتا ہے۔
- Strict mode غلطیوں کو پکڑنے اور بہتر کوڈنگ کے لیے ضروری ہے۔
- یہ گلوبل ویری ایبلز، اور چھپی ہوئی غلطیوں سے بچاتا ہے۔
- یہ جاوا اسکرپٹ کی کارکردگی اور سیکیورٹی کو بہتر بناتا ہے۔
یہ باب محمد رضا (SMRIT - Smart Modern Revolutionary IT Training) کی جانب سے پیش کیا گیا ہے۔ 🚀