Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Quickstart Data Types and Variables Creating Variables

Kupe Kouratoras
Kupe Kouratoras
888 Points

what is a string

i don't really understand the question

scripts.js
var myname = "what is your name?";
prompt(myname);

var KJ = prompt(myname);
alert("hello " + KJ + "!");

3 Answers

eslam said
PLUS
eslam said
Courses Plus Student 6,734 Points

A string is a data type is javascript, data types including :

  • Strings ( Strings are written with quotes. You can use single or double quotes )
   "hello world"
  • Numbers
   10
  • Booleans ( Boolean is a value its either true or false )
   var x = 10;
   var y = 5;
   x > y // returns true

   var x = 1
   var y = 4;
   x > y // returns false
  • Arrays ( Think of an array like a list of items, arrays are written with square brackets )
   var names = ["Wesam", "John", "Nahla"];
  • Objects ( Think of objects like a collection of properties objects are written with curly braces )
   var user = {
      name: "stuve",
      age: 25,
      country: "sweden"
   }
  • Undefined ( a variable without a value, has the value undefined )
   var score; // returns undefined
  • Null
   Null is the absence of value ( the data type of null in javascript is an object )

You can know the type of anything by using the typeof operator

typeof 5; // returns a number
typeof "hello" // returns a string
typeof ["Wesam", "John", "Nahla"] // returns object despite it's an array javascript arrays are objects
Oskar Lundberg
Oskar Lundberg
9,510 Points

I'm not very familiar with JavaScript, and I don't know if this will help. But the following passed the Challenge:

var myName = "Oskar Lundberg"

var myAge = 20

var message = myName + " is " + myAge

alert(message)

I hope it somehow helps :D