خلاصه جاوااسکریپت با بهزاد فرهادی جلسه ۸
مقدمه
در این جلسه، بهزاد فرهادی آموزش جاوا اسکریپت را ادامه میدهد و مفاهیمی مانند اشیاء (Objects)، ویژگیها (Properties)، و متدها (Methods) را بررسی میکند. همچنین برخی از متدهای پرکاربرد رشته و ساختارهای شرطی مورد بررسی قرار میگیرند. این جلسه شامل تمرینهایی برای درک بهتر مفاهیم است.
موضوعات اصلی پوشش دادهشده
۱. معرفی اشیاء و ویژگیها
- در جاوا اسکریپت، اشیاء مجموعهای از ویژگیها و متدها هستند.
- ویژگیها مقدارهایی را در خود نگه میدارند، در حالی که متدها عملیات خاصی را روی اشیاء انجام میدهند.
- مثال: یک دفترچه تلفن را میتوان یک شیء در نظر گرفت که تعداد صفحات، اسامی و شمارههای تلفن ویژگیهای آن هستند، و جستجوی یک شماره تلفن متد آن محسوب میشود.
- در جاوا اسکریپت، حتی رشتهها نیز اشیائی با ویژگیها و متدهای داخلی هستند.
۲. دسترسی به ویژگیهای یک شیء
- برای دسترسی به ویژگیهای یک شیء از نقطه (
.
) استفاده میشود. - مثال: ویژگی
.length
در رشته تعداد کاراکترها را برمیگرداند. - نمونه کد:
let name = "Behzad";
console.log(name.length); // خروجی: ۶
۳. متدهای رشتهای
چند متد مهم برای کار با رشتهها معرفی شدند:
الف) متد toUpperCase()
- تمامی حروف یک رشته را به حروف بزرگ تبدیل میکند.
- نمونه:
let name = "Mohammad";
console.log(name.toUpperCase()); // خروجی: "MOHAMMAD"
ب) متد includes()
- بررسی میکند که آیا یک کاراکتر یا زیررشته در یک رشته وجود دارد یا خیر.
- اگر مقدار مورد نظر وجود داشته باشد،
true
و در غیر این صورتfalse
برمیگرداند. - نمونه:
let name = "Behzad";
console.log(name.includes("z")); // خروجی: true
console.log(name.includes("x")); // خروجی: false
نتیجهگیری
در این جلسه، مفاهیم پایهای اشیاء، ویژگیها و متدهای جاوا اسکریپت به صورت عملی بررسی شدند. دانشجویان با نحوه دسترسی و تغییر ویژگیهای رشته آشنا شدند و متدهای مفیدی را برای کار با رشتهها یاد گرفتند. تمرینهای این جلسه به درک بهتر این مفاهیم کمک میکند.
Summary of “JavaScript by Behzad Farhadi – Session 08”
Introduction
In this session, Behzad Farhadi continues his JavaScript training series, focusing on objects, properties, and methods. He reviews important string methods and conditional structures. The session includes practical exercises to reinforce the concepts.
Main Topics Covered
1. Introduction to Objects and Properties
- Objects in JavaScript are structures that hold properties and methods.
- Properties store values, while methods define actions that can be performed on the object.
- Example: A phonebook can be considered an object where the pages, names, and phone numbers are properties, and searching for a number is a method.
- In JavaScript, strings themselves are considered objects with built-in properties.
2. Accessing Object Properties
- Properties can be accessed using dot notation (
object.property
). - Example: The
.length
property of a string returns the number of characters. - Demonstration:
let name = "Behzad";
console.log(name.length); // Output: 6
3. String Methods
Several string methods are introduced:
a) toUpperCase()
Method
- Converts all characters in a string to uppercase.
- Example:
let name = "Mohammad";
console.log(name.toUpperCase()); // Output: "MOHAMMAD"
b) includes()
Method
- Checks if a string contains a specific character or substring.
- Returns
true
if found, otherwisefalse
. - Example:
let name = "Behzad";
console.log(name.includes("z")); // Output: true
console.log(name.includes("x")); // Output: false
Conclusion
The session provides a practical introduction to objects, properties, and methods in JavaScript. By demonstrating how to access and manipulate string properties and methods, students gain foundational knowledge essential for JavaScript programming. The exercises reinforce learning by encouraging hands-on practice.
