1

What I have so far

This is what my code currently look like:

var a, b, c = "hello world " + "I am here " + "my name is hamza";

What my problem is

But only c is defined whereas a and b are undefined.

a // returns: undefined
b // returns: undefined
c // returns: "hello world I am here my name is hamza"

What I'd like to achieve

How can I have all three variables defined with each one of the three string literals in a single statement?

// How to do that in a single statement instead of three?
var a = "hello world";
var b = "I am here";
var c = "my name is hamza";
0

2 Answers 2

2

I guess this what you wannna achieve.

var a = "hello world ", b =  "I am here" , c = "my name is hamza"
Sign up to request clarification or add additional context in comments.

Comments

2

Try destructuring assignment:

const [ a, b, c] = [ 'hello world', 'I am here', 'my name is hamza'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.