Programming concepts class3
Programming concepts class3
#### **JavaScript**
```javascript
let temperature = 20;
if (temperature > 25) {
console.log("It's a hot day!");
}
```
#### **Python**
```python
temperature = 20
if temperature > 25:
print("It's a hot day!")
```
- **Key Difference**: Python does not require parentheses around the condition and
uses indentation instead of curly braces `{}` to define blocks.
---
#### **JavaScript**
```javascript
let age = 18;
if (age >= 21) {
console.log("You can drink in the US.");
} else {
console.log("You're not old enough.");
}
```
#### **Python**
```python
age = 18
if age >= 21:
print("You can drink in the US.")
else:
print("You're not old enough.")
```
- **Key Difference**: Python eliminates `{}` and uses indentation for defining
blocks.
---
#### **JavaScript**
```javascript
let score = 75;
if (score >= 90) {
console.log("Grade: A");
} else if (score >= 80) {
console.log("Grade: B");
} else if (score >= 70) {
console.log("Grade: C");
} else {
console.log("Grade: F");
}
```
#### **Python**
```python
score = 75
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: F")
```
- **Key Difference**: Python uses `elif` instead of `else if`, making it slightly
more concise.
---
---
### **Truthy & Falsy Values**
- JavaScript considers non-boolean values like `0`, `""`, `null`, and `undefined`
as **falsy**.
- Python treats `None`, `0`, `""`, and empty collections like `[]`, `{}` as
**falsy**.
---
Would you like an example that applies to a project you're working on? Since you're
skilled in JavaScript and Python, I can tailor the explanation to a real-world
scenario you're tackling!