Kelish Rai's profileExpert

Kelish Rai

Technical Content Writer @Programiz

Answered 69 questions


About

Hi, I'm Kelish, Technical Content Writer at Programiz. I break down complex programming concepts and turn them into easy-to-understand articles, tutorials, and courses. I'm also a developer at heart—I love solving coding problems, exploring algorithms, and staying updated with the latest tech stuff. If I'm not writing content, there's a good chance I'm working on a side project.

Answered by Kelish Rai
Kelish Rai
Expert
2 weeks ago
Kelish Rai answered

The difference between innerHTML and outerHTML is in what part of the element they work with.

  • innerHTML gives you just the content inside an element.

  • outerHTML gives you the entire element itself, including the tag.

Consider this code:

Hello

And this JavaScript:

const hero = document.querySelector(".demo");

Now if you do:

console.log(hero.innerHTML);

You'll get:

Hello

But if you do:

console.log(hero.outerHTML);

You'll get:

Hello

So, outerHTML includes the entire element, while innerHTML only includes what's inside it.

Simply put, use innerHTML if you want to change the content inside an element, and use outerHTML if you want to change the element itself.

This question was asked as part of the JavaScript in Browser course.
Kelish Rai
Expert
2 weeks ago
Kelish Rai answered

You're right—using if vs elif isn't drastically different in many cases. You can even use multiple if statements instead of elif to check several conditions.

However, it's important to understand how Python reads and handles if...elif...else compared to a series of if...if...if.

When you use if...elif...else, Python stops checking as soon as it finds a condition that's true. On the other hand, if you use multiple if statements, Python will check each one separately, even if an earlier one was already true.

Here's a quick example to show the difference:

1. Using if...elif...else:

x = 10

if x > 5:
    print("Greater than 5")
elif x > 3:
    print("Greater than 3")
elif x > 7:
    print("Greater than 7")

Output:

Greater than 5

Here, only the first block runs because its condition is true.

2. Using if...if...if:

x = 10

if x > 5:
    print("Greater than 5")

if x > 3:
    print("Greater than 3")

if x > 7:
    print("Greater than 7")

Output:

Greater than 5  
Greater than 3 
Greater than 7

Here, all conditions are checked separately, so all print statements are executed.

Also, it’s worth noting that using multiple if statements is quite common in real programs, especially when you're checking conditions that aren't mutually exclusive. You'll be using them a lot as you build more complex logic.

Python
This question was asked as part of the Learn Python Basics course.
Kelish Rai
Expert
2 weeks ago
Kelish Rai answered

The break statement is used to stop a loop based on certain conditions. It can be used to terminate any kind of loop—for, while, etc.

Here’s an example:

class Main {
    public static void main(String[] args) {
        for (int i = 1; i <= 10; i++) {
            System.out.println("Hello Dhanush");
            break;
        }
    }
}

Output

Hello Dhanush

According to the for loop’s condition (i <= 10), the loop is supposed to run 10 times. But because we’ve used break right after the first print statement, the loop stops immediately after the first iteration.

Now let’s say we want to stop the loop after 5 iterations instead of immediately:

class Main {
    public static void main(String[] args) {
        for (int i = 1; i <= 10; i++) {
            System.out.println("Hello Dhanush");

            if (i == 5) {
                break;
            }
        }
    }
}

Output

Hello Dhanush
Hello Dhanush
Hello Dhanush
Hello Dhanush
Hello Dhanush

Here, Hello Dhanush is printed 5 times. That’s because we’ve used the condition if (i == 5) to break out of the loop when i reaches 5.

Note: break is very useful when you want to exit a loop early, without having to wait for the loop's natural condition to end. You can apply this same logic in different scenarios, like stopping a search when the target is found.

Java
This question was asked as part of the Learn Java Basics course.
Kelish Rai
Expert
2 weeks ago
Kelish Rai answered

You're right that in JavaScript, there's not much difference between using single quotes (' ') and double quotes (" "), as both are used to define strings.

But in Java, there's an important distinction:

  • Single quotes are used for single characters — this data type is called char.

  • Double quotes are used for strings, which can contain multiple characters.

Here's an example:

// Single character using single quotes
char letter = 'A';

// A string of characters using double quotes
String word = "Hello";

If you try to store multiple characters inside single quotes like this:

char letter = 'Hello'; // This will cause an error

Java will throw an error because char can only hold a single character, not a sequence.

In short,

  • char is meant for a single character (like 'A', 'b', '5', or '@').

  • String is meant for text that can have one or many characters (like "Hello", "123", "Good morning").

Java
This question was asked as part of the Learn Java Basics course.
Kelish Rai
Expert
last month
Kelish Rai answered

Yes, a dictionary can have a key with an empty value. Since "empty values" can be represented in different ways depending on what you're trying to express, two common options are:

my_dict = {"name": ""}    # Empty string
my_dict = {"name": None}    # None indicates the value is intentionally left empty or unknown

Both are valid, and which one you use depends on your intention. An empty string might mean "this was filled in but is blank", while None often means "this hasn’t been set yet".

If you want to remove or reset the value without deleting the key itself, you don’t delete it—you just update it to an empty value:

my_dict["name"] = None

That way, the key "name" still exists in the dictionary, but its value is clearly empty or unassigned.

This is useful when you want to preserve the structure of the data or signal that a value is missing but not lost.

Python
This question was asked as part of the Learn Python Basics course.
ndekwe auxile
last month
Ndekwecountry asked
Kelish Rai
Expert
last month
Kelish Rai answered

Scalable code is code that can handle growth, like more users, more data, or bigger problems, without needing to be completely rewritten.

Let me explain with a simple example:

Imagine you're building a house using LEGO blocks.
At first, the house is built for a small family of four, so just a few blocks are enough.

But what if the family grows?
If you’ve made the house scalable, you can add more rooms and floors just by snapping on more blocks.

However, if it wasn’t built with that flexibility, you'd have to tear the whole thing down and start over, which takes time and effort.

Similarly in coding:
If your code was originally designed to handle 100 users, and tomorrow that grows to 1,000 or even 100,000, you should be able to scale it up smoothly, without rewriting everything from scratch.

C++
This question was asked as part of the DSA with C++ course.
Kelish Rai
Expert
last month
Kelish Rai answered

Real numbers are the ones you're already familiar with—like 2, -5, 3.14, 0, or even square roots like √2. These are numbers you can easily picture in everyday life, and they represent measurable quantities, like distances, temperatures, or amounts of money.

Imaginary numbers, on the other hand, are based on something a bit trickier. They're built around the concept of the square root of -1, which we represent as i. Since you can't take the square root of a negative number in the real number system, imaginary numbers fill this gap. For example, 2i or -3i are imaginary numbers.

The real magic happens when you combine real numbers with imaginary numbers. When you do that, you get a complex number, which looks like this: 3 + 2i (a real part, 3, and an imaginary part, 2i).

It’s all just another way to extend the world of numbers and solve more complex problems that you can't with just real numbers.

C
This question was asked as part of the Learn C Programming course.
Kelish Rai
Expert
last month
Kelish Rai answered

You're absolutely right that both else if and switch can be used to handle multiple conditions, and it often comes down to personal preference or the situation.

However, there are a few advantages to using switch:

  • Cleaner code: When you're comparing a single variable to many possible values, switch often results in cleaner and more readable code than multiple else if statements.

  • Efficiency: In some cases, switch can be more efficient. When you have many conditions to check for the same variable, switch can sometimes make the process faster than evaluating each condition one by one as else if does.

Here’s a simple example in C++ to show the difference:

// Using else if

#include 
using namespace std;

int main() {
    int day = 3;

    if (day == 1) {
        cout << "Monday";
    } else if (day == 2) {
        cout << "Tuesday";
    } else if (day == 3) {
        cout << "Wednesday";
    } else {
        cout << "Another day";
    }

    return 0;
}

In this example, each condition is checked one by one until a match is found.

// Using switch

#include 
using namespace std;

int main() {
    int day = 3;

    switch(day) {
        case 1:
            cout << "Monday";
            break;
        case 2:
            cout << "Tuesday";
            break;
        case 3:
            cout << "Wednesday";
            break;
        default:
            cout << "Another day";
    }

    return 0;
}

Here, the switch allows the program to directly jump to the matching case block, which can be more efficient and helps the logic feel more organized.

Both approaches work well, and it’s good to be comfortable with both. When dealing with a single variable and multiple constant values, switch tends to be a cleaner and often faster choice.

C++
This question was asked as part of the Learn C++ Basics course.
Kelish Rai
Expert
last month
Kelish Rai answered

The main difference between arrays and vectors is that an array is a fixed-size collection of elements, whereas a vector can grow or shrink as needed.

Both are used to store multiple values, but they work a bit differently.

With arrays, once you define the size, it can't be changed. For example:

int arr[5];

Here, you've got space for exactly 5 integers—no more, no less. If you later want to store 6 or more values, you'll need to create a new array and manage copying manually.

Vectors, on the other hand, are part of the C++ Standard Library and are more flexible. You can start with an empty vector and keep adding elements using push_back():

#include 
using namespace std;

vector nums;    // Starts empty
nums.push_back(10);    // Adds 10 to the vector
nums.push_back(20);    // Adds 20

The vector automatically resizes itself in the background as you add elements—no need to specify the size in advance.

Note: If you're working with a known, fixed number of values and performance is critical, arrays can be slightly faster. But in most cases, vectors are preferred for their ease of use and flexibility.

C++
This question was asked as part of the Learn C++ Basics course.
Kelish Rai
Expert
last month
Kelish Rai answered

I understand that you're hearing mixed opinions about Java.

For beginners, Java can feel a bit overwhelming at first, mainly because it has more rules and structure compared to some other languages like Python. For example, in Python you can print something with just:

print("Hello")

But in Java, even the simplest program needs a full structure like this:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

This extra structure can feel like a lot when you're just starting out.

However, once you get the hang of it—just like with any other language—it becomes much easier and more natural to work with. You’ll soon feel comfortable using Java to write code.

Also, the structure and rules that might seem tough at first are actually what make Java so powerful and widely used in the industry. Its strictness helps avoid many bugs and makes large-scale software development more manageable.

Java is also used in a lot of real-world applications—from Android apps to banking systems—so the effort you put in can really pay off.

The key, as with anything, is to take it step by step. Once you're comfortable with the basics, it’ll start making more sense. It might feel challenging at the start, but with practice, it’ll definitely get smoother.

Java
This question was asked as part of the Learn Java Basics course.