30
loading...
This website collects cookies to deliver better user experience
var a == "code";
var b == "wa.rs";
var name == a + b;
name
. So we need to figure out why the given code isn't doing that properly.=
.==
. In JavaScript, there is more than one way to check for equality, but that is a story for another post.==
to assign values to all three variables when it should be using =
.+
to concatenate--meaning put together--two strings. It's as simple as that. In JavaScript we can use the plus sign as a shortcut to put strings together.const greeting = "Hello, ";
const myName = "Dylan";
const sentence = greeting + myName + ".";
console.log(sentence);
// "Hello, Dylan."
var
keyword with the const
keyword.var
was the only way to declare a variable in JavaScript.const
and let
.const
is used for variables that are not allowed to be reassigned.let
is used for variables that are allowed to be reassigned.const
to declare them.==
to =
, which is the crux of the problem.const a = "code";
const b = "wa.rs";
const name = a + b;
a
and b
in this problem with another technique called string interpolation. const regularString = "This is a regular string.";
const templateString = `This is a template string.`;
const myName = "Dylan";
const templateStringWithVariable = `My name is ${myName}.`;
console.log(templateStringWithVariable);
// "My name is Dylan."
const a = "code";
const b = "wa.rs";
const name = `${a}${b}`;