JavaScript Strings, Variables & Logic
String Operations in JavaScript
• Declaring strings: let firstName = "Alice";
• Template literals: `Hello ${name}`
String Manipulations
• .length, .toUpperCase(), .toLowerCase()
• Character access with str[0]
String Searching & Slicing
• .indexOf(), .includes()
• .slice(), .substring()
Replacing and Splitting
• replace, replaceAll with regex
• split(" "), trim(), repeat()
JavaScript vs Python – Strings
Concept JavaScript Python
Interpolation `Hi ${name}` f"Hi {name}"
Multiline Backticks `` Triple quotes
Repetition "Ha!".repeat(3) "Ha" * 3
let vs var vs const
• let: block scoped, changeable
• var: function scoped, redeclarable
• const: block scoped, constant
Scope Differences
• Block vs function scope
• Example with var x = "outside" vs let y =
"outside"
Escape Sequences & Booleans
• \n, \" , \\, \t explained
• Boolean logic: &&, ||, !
Boolean Example
• isLoggedIn, isAdmin
• Expressions: canEdit, canView, isGuest
Summary
• Strong string handling in JS
• Control with logical and scope operations