Difference between Argument and String

drawBoxes('ooo www ggg')

In the aforementioned example, it seems there are 1 string but not sure about the argument.
In this particular example, what is the difference between argument and string?

Great question!

A string is anything with quote marks around it, for example 'this is a string'. An argument is something that is ‘passed’ to a function (it’s inside the parentheses of a function), for example in drawBox(red), red is the argument.

In your example, drawBox('ooo www ggg'), 'ooo www ggg' is both a string and an argument.

Hopefully this makes sense,
H :slight_smile:


Which one ia correct ?
Var x = ’ 1 ’ ;
Var x = 1;
Coz when i applied in print(x) function the result is same , Does this mean that the string does not have to be a letters, words ?
Is it posibble string contain only one word ? Like var = ‘a’; ?

Good question. Strings are not limited to just letters, and can be any length. They can even be empty and contain nothing at all, for example:
var x = ''

1 and '1' may look similar, but the difference is that they are different data types.

1 is a number.
'1' is a string.

When you use the print() function, they will appear the same when they are printed to the console.

However, if you tried to do math with strings, you’d run into errors.

For example:

2 + 5 // This gives us the number 7

'2' + '5' // This gives us the string '25'

Hope this explains things a bit! Let me know if you have any questions.

1 Like