Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,985 members, 7,825,066 topics. Date: Sunday, 12 May 2024 at 04:22 AM

I Need Assistance With This Code On Javascript - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need Assistance With This Code On Javascript (344 Views)

Is It Necessary To Read A Book On Javascript? / Companies Working On Javascript Framework / Good Book On Javascript (2) (3) (4)

(1) (Reply) (Go Down)

I Need Assistance With This Code On Javascript by Winningbot: 10:17am On Jun 17, 2022
Good morning to you. Firstly I want to appreciate all who have been assisting me here with my questions, I'm really grateful.

Now my question

Can someone please explain why if I try to run a string on my vs code the output is same as a number?

Like the example on my laptop screen

I typed
Var num1 = 10;
Var num3 = "20";

And the output is
10
20

I thought one should be
10 and the string "20"

Pls someone should explain pls

Re: I Need Assistance With This Code On Javascript by Machinegun91(m): 10:27am On Jun 17, 2022
I don't know anything about what you are talking about
Re: I Need Assistance With This Code On Javascript by Enskynelson(m): 10:31am On Jun 17, 2022
Breathtaker
Re: I Need Assistance With This Code On Javascript by Winningbot: 10:38am On Jun 17, 2022
Machinegun91:
I don't know anything about what you are talking about
okay boss.

Just like the screenshot above if you check the output you will see a square bracket but in vs code nothing like that. It looks like that's how it is with vs code because I just ran a string code and I didn't see any square bracket.

Re: I Need Assistance With This Code On Javascript by jbreezy: 10:44am On Jun 17, 2022
Winningbot:
Good morning to you. Firstly I want to appreciate all who have been assisting me here with my questions, I'm really grateful.

Now my question

Can someone please explain why if I try to run a string on my vs code the output is same as a number?

Like the example on my laptop screen

I typed
Var num1 = 10;
Var num3 = "20";

And the output is
10
20

I thought one should be
10 and the string "20"

Pls someone should explain pls
Lol they are still different data types... you can confirm this by "console.log(typeof num1, typeof num3) or console.log(num1 === num 3)"
Re: I Need Assistance With This Code On Javascript by Nobody: 10:52am On Jun 17, 2022
Winningbot:
Good morning to you. Firstly I want to appreciate all who have been assisting me here with my questions, I'm really grateful.

Now my question

Can someone please explain why if I try to run a string on my vs code the output is same as a number?

Like the example on my laptop screen

I typed
Var num1 = 10;
Var num3 = "20";

And the output is
10
20

I thought one should be
10 and the string "20"

Pls someone should explain pls

Try this

var numOne = 10;
var numTwo = 20;
var sum = numOne+numTwo;
Console.log("Sum = " + sum);

The mistake you made is that you consoled them differently so it will treat them as independent variables
Re: I Need Assistance With This Code On Javascript by VitoriaAcerta: 11:27am On Jun 17, 2022
jbreezy:
Lol they are still different data types... you can confirm this by "console.log(typeof num1, typeof num3) or console.log(num1 === num 3)"

Correct answer.
Basically, printing a string directly to console will strip the quotes.
If you console.log both in chrome console, both variables will have different colours
And also, if you console.log( [num1, num2]), you'll still it the way you actually expect it to be
Re: I Need Assistance With This Code On Javascript by Nobody: 1:07pm On Jun 17, 2022
Winningbot:
Good morning to you. Firstly I want to appreciate all who have been assisting me here with my questions, I'm really grateful.

Now my question

Can someone please explain why if I try to run a string on my vs code the output is same as a number?

Like the example on my laptop screen

I typed
Var num1 = 10;
Var num3 = "20";

And the output is
10
20

I thought one should be
10 and the string "20"

Pls someone should explain pls
JavaScript ignores quotes unless you want the quote to show then you'll use single quotes inside
By the way, how is your JS running in the terminal, is it node you're using ?
Re: I Need Assistance With This Code On Javascript by Winningbot: 2:05pm On Jun 17, 2022
Think4Myself:

JavaScript ignores quotes unless you want the quote to show then you'll use single quotes inside
By the way, how is your JS running in the terminal, is it node you're using ?
yes boss
Re: I Need Assistance With This Code On Javascript by Winningbot: 2:06pm On Jun 17, 2022
jbreezy:
Lol they are still different data types... you can confirm this by "console.log(typeof num1, typeof num3) or console.log(num1 === num 3)"
thanks boss
Re: I Need Assistance With This Code On Javascript by Winningbot: 2:06pm On Jun 17, 2022
sollolucci77:


Try this

var numOne = 10;
var numTwo = 20;
var sum = numOne+numTwo;
Console.log("Sum = " + sum);

The mistake you made is that you consoled them differently so it will treat them as independent variables
alright sir thank you for your time

(1) (Reply)

. / Journey Into Tech: My Challenges, Goals, Aspirations / Earn Up To $5000 Per Month Working For Top US And Silicon Valley Companies

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.