Today, I explored Strings in JavaScript — one of the most common and powerful data types we use to handle text. Strings are sequences of characters enclosed in quotes (' ', " ", or ` `). Let’s dive into some key concepts 1. Creating Strings let single = 'Hello'; let double = "World"; let template = `Hello, World!`; 🔹 2. String Concatenation Joining multiple strings together: let firstName = "John"; let lastName = "Doe"; let fullName = firstName + " " + lastName; console.log(fullName); // John Doe You can also use template literals for cleaner syntax: let fullName2 = `${firstName} ${lastName}`; console.log(fullName2); // John Doe String Length let text = "JavaScript"; console.log(text.length); // 10 Accessing Characters let word = "Code"; console.log(word[0]); // C console.log(word.charAt(2)); // d Common String Methods let message = " Hello JavaScript! "; console.log(message.toUpperCase()); // " HELLO JAVASCRIPT! " console.log(message.toLowerCase()); // " hello javascript! " console.log(message.trim()); // "Hello JavaScript!" console.log(message.includes("Java")); // true console.log(message.replace("Hello", "Hi")); // " Hi JavaScript! " Splitting and Joining Strings let sentence = "I love JavaScript"; let words = sentence.split(" "); // ["I", "love", "JavaScript"] console.log(words.join("-")); // "I-love-JavaScript" Key takeaway: Strings are everywhere — from user inputs to API responses. Understanding string methods will make your JavaScript code more efficient and expressive. #100DaysOfCode #JavaScript #CodingChallenge #WebDevelopment #LearnInPublic #CodeNewbie
Exploring Strings in JavaScript: Key Concepts and Methods
More Relevant Posts
-
Coercion: The hidden mechanics of JS type conversion JavaScript can do some surprising things when combining different data types — and it’s not “random”, it follows a set of internal rules. I built a tiny Coercion Lab that: • Breaks down implicit & explicit type conversion • Shows how JavaScript compares values (== vs ===) • Demonstrates why expressions you see every day behave the way they do • Helps you build deeper intuition for debugging and writing safe code I did my best to complete it, waiting for your feedback 😊 Repo: https://lnkd.in/gfAyiXjd Tech: JavaScript (ES2023), Node, CLI Goal: Understand how JavaScript thinks
To view or add a comment, sign in
-
🎯 Function Parameters & Arguments in JavaScript — Pass Data Like a Pro! Functions become powerful when you can send data to them — that’s where parameters and arguments come in! Let’s break it down 👇 --- 💡 Definition: Parameters are variables listed in the function definition. Arguments are the actual values you pass when calling the function. --- 🧩 Example: function greet(name) { // 'name' is a parameter console.log("Hello, " + name + "! 👋"); } greet("Kishore"); // 'Kishore' is an argument greet("Santhiya"); ✅ Output: Hello, Kishore! 👋 Hello, Santhiya! 👋 --- ⚙ Multiple Parameters Example: function add(a, b) { console.log("Sum:", a + b); } add(5, 10); add(3, 7); ✅ Output: Sum: 15 Sum: 10 --- 🧠 Key Points: Parameters are placeholders. Arguments are real data. You can pass default values too: function greet(name = "Guest") { console.log("Welcome, " + name); } greet(); // Output: Welcome, Guest --- 🔖 #JavaScript #Functions #WebDevelopment #Frontend #JSConcepts #CodingTips #LearnToCode #WebDevCommunity #100DaysOfCode #DeveloperJourney #ProgrammingBasics
To view or add a comment, sign in
-
🧠 JavaScript typeof Explained: Understanding Data Types Made Simple When coding in JavaScript, one of the most common tasks is checking what type of data you’re working with. That’s where the typeof operator comes in! --- 💡 What is typeof? typeof is a built-in JavaScript operator that tells you the type of a variable or value. It’s like asking JavaScript: > “Hey, what exactly is this thing I’m working with?” --- 🧩 Syntax: typeof variableName; or typeof(value); --- 🔍 Examples: typeof "Hello"; // "string" typeof 42; // "number" typeof true; // "boolean" typeof {}; // "object" typeof []; // "object" (arrays are technically objects) typeof undefined; // "undefined" typeof null; // "object" (a known JavaScript quirk!) typeof function(){}; // "function" --- 🪄 Why It Matters The typeof operator is super useful when: Debugging your code 🐞 Validating user input 🧍♂️ Writing clean, bug-free programs 💻 --- ⚙️ Pro Tip: If you want to check if something is an array, don’t use typeof. Instead, use: Array.isArray(value); --- 🚀 Final Thoughts: Understanding the typeof operator helps you master JavaScript’s dynamic typing system. It’s a simple but powerful tool for keeping your code organized and error-free. Start experimenting with typeof today—you’ll quickly see how handy it is! #codecraftbyaderemi #webdeveloper #html #javascript #frontend
To view or add a comment, sign in
-
-
Here's the corrected JavaScript code that outputs the expected JSON object: ```javascript const response = JSON.parse(response); const sampleJSON = JSON.parse(sampleJSON); console.log(`sampleJSON: ${sampleJSON}`); console.log(`Flow response: ${response}`); ``` In the original code, the `JSON.parse` method was trying to parse the `response` string as a JSON object, but it's working with the JSON string as a string. To convert it to a JSON object, we need to use the `JSON.stringify` method with a replacer function that replaces the special characters with their ASCII codes. Here's the updated code with the `JSON.stringify` method and a replacer function that replaces special characters with their ASCII codes: ```javascript const response = JSON.parse(response); const sampleJSON = JSON.parse(sampleJSON); console.log(`sampleJSON: ${sampleJSON}`); console.log(`Flow response: ${response}`); ``` This code will output the expected JSON object with the `FullName` and `ORDER_ID` fields, and the `AMOUNT` field as a JSON object: ```json { "FullName": "John Doe", "ORDER_ID": "373474766", "AMOUNT": "4
To view or add a comment, sign in
-
🔥 Day 33 of #100DaysLearningChallenge 🧠 Topic: How to Handle JSON Files in JavaScript (Node.js) 📘 Overview Today, I learned how to read and access data from a JSON file using JavaScript in Node.js. JSON (JavaScript Object Notation) is one of the most common formats for storing and exchanging data — and knowing how to handle it in JS is super useful! 📂 What the JSON File Contains: ✅ Simple values → strings, numbers, booleans ✅ Nested objects → e.g. a client object with multiple properties ✅ Arrays → lists of numbers or strings ✅ Arrays of objects → e.g. a score array containing multiple records ⚙️ How It Works 1️⃣ Loading the JSON File We can use require() in Node.js to import the JSON file. It automatically parses it and returns a JavaScript object. ✔️ typeof data → returns "object" 2️⃣ Iterating Through the Data We loop through each property using for...in. Depending on the type of data, we handle it differently: Simple values (string, number, boolean): print key-value pairs Arrays: If it contains numbers → print each number If it contains objects → use a nested loop to access each property Nested objects: loop through their internal keys and values 💡 Key Concepts Learned 🔹 Type Checking: typeof helps detect if a value is a primitive or object 🔹 Array Detection: instanceof Array distinguishes arrays from objects 🔹 Nested Loops: Used for deep data traversal 🔹 Error Handling: Always good to wrap in try-catch for safety 🧩 Expected Output Example: name - Rohan age - 34 is_active - true id - A101 username - rohan123 30 40 25 60 f1 - 23 f2 - 25 f3 - 27 ... This method allows reading all data — even deeply nested structures — easily! 🙏 Special Thanks to Saurabh Shukla Sir for explaining everything so clearly and practically. 💻 My Code: https://lnkd.in/d4TnHZGj) #100DaysLearningChallenge #JavaScript #NodeJS #JSON #WebDevelopment #Backend #Programming #DataHandling #CodingJourney
To view or add a comment, sign in
-
🔓 JS Tip: Stop Manually Assigning Object Properties! 🔓 Tired of writing var name = user.name; var email = user.email;? Destructuring lets you "pull apart" objects and arrays and grab just the pieces you need, all in one line. ❌ The Old Way (One by One) js code - var user = { id: 123, name: 'Alex', email: 'alex@example.com' }; var id = user.id; var name = user.name; var email = user.email; --- ✅ The New Way (Destructuring) js code - const user = { id: 123, name: 'Alex', email: 'alex@example.com' }; // "From 'user', get 'id', 'name', and 'email' // and put them in variables with the same name." const { id, name, email } = user; ---- 🔥 Why it's better: It's incredibly clean and efficient, especially with large objects from an API. You declare what data you want, not the tedious steps to get it. It's also perfect for function arguments and React props. 👉 View My New Services - https://lnkd.in/g5UaKeTc 🎇 Do you want more tips like this? Do follow and write "Yes" in the comment box. #javascriptTips #JavaScript #JSTips #ES6 #Developer #Programming #WebDev #ReactJS #NodeJS #Coding #TechTips #WebDeveloper #MdRedoyKayser #Webxpanda #WordPress
To view or add a comment, sign in
-
-
Change your old methods for writing a JavaScript Code - Shorthand's for JavaScript Code 1. Shorthand for if with multiple OR(||) conditions if (car === 'audi' || car === 'BMW' || car === 'Tesla') { //code } In a traditional way, we used to write code in the above pattern. but instead of using multiple OR conditions we can simply use an array and includes. Check out the below example. if (['audi', 'BMW', 'Tesla', 'grapes'].includes(car)) { //code } if(obj && obj.tele && obj.tele.stdcode) { console.log(obj.tele .stdcode) } Use optional chaining (?.) to replace this snippet. console.log(obj?.tele?.stdcode); if (name !== null || name !== undefined || name !== '') { let second = name; } The simple way to do it is... const second = name || ''; switch (number) { case 1: return 'Case one'; case 2: return 'Case two'; default: return; } Use a map/ object const data = { 1: 'Case one', 2: 'Case two' }; //Access it using data[num] function example(value) { return 2 * value; } Use the arrow function const example = (value) => 2 * https://lnkd.in/gjf7ViX5
To view or add a comment, sign in
-
Change your old methods for writing a JavaScript Code - Shorthand's for JavaScript Code 1. Shorthand for if with multiple OR(||) conditions if (car === 'audi' || car === 'BMW' || car === 'Tesla') { //code } In a traditional way, we used to write code in the above pattern. but instead of using multiple OR conditions we can simply use an array and includes. Check out the below example. if (['audi', 'BMW', 'Tesla', 'grapes'].includes(car)) { //code } if(obj && obj.tele && obj.tele.stdcode) { console.log(obj.tele .stdcode) } Use optional chaining (?.) to replace this snippet. console.log(obj?.tele?.stdcode); if (name !== null || name !== undefined || name !== '') { let second = name; } The simple way to do it is... const second = name || ''; switch (number) { case 1: return 'Case one'; case 2: return 'Case two'; default: return; } Use a map/ object const data = { 1: 'Case one', 2: 'Case two' }; //Access it using data[num] function example(value) { return 2 * value; } Use the arrow function const example = (value) => 2 * https://lnkd.in/gjf7ViX5
To view or add a comment, sign in
-
Going back to basics 🌱 Where Javascript stores Your data "Stack" vs "Heap Memory" ? have you ever wondered where your values are actually stored ? JavaScript manages memory in two main places - 1. "Stack Memory" Used for primitive values (like numbers, strings, booleans) and function calls. It is small but super fast. 2. "Heap Memory" Used for objects, arrays, and functions (reference types). It is larger and used for dynamic data that can grow or shrink. When Javascript executes the code, the "Stack" holds the variable name directly, while user stores only a reference (a pointer) to the object, and that object actually lives in the "Heap". So when you pass "user" around, you are really passing a "reference" to the data in the "heap" not the data itself. #JavaScript #Frontend
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development