3 Questions
Which of the following is NOT a data type in JavaScript?
Decimal
What is the result of the following code: '5' + 3?
'53'
What is the output of the following code?
var x = 5; function add(num) { var x = 2; return x + num; } console.log(add(3));
7
Study Notes
JavaScript Data Types
- There are specific data types in JavaScript, but the options are not provided.
String Concatenation
- In JavaScript, when a string is added to a number using the '+' operator, the number is converted to a string and then concatenated.
- The result of
'5' + 3
is'53'
.
Variable Scope and Functions
- In a function, a variable with the same name as a global variable can be declared, which will have a local scope.
- The local variable will override the global variable within the function.
- In the given code,
var x
is declared globally with a value of 5, but within theadd
function, anothervar x
is declared with a value of 2. - The
add
function will use the localx
value, which is 2, and add the providednum
to it. - The output of the code will be
5
, which is the result of2 + 3
.
Test your knowledge of JavaScript with our quiz! Challenge yourself with questions on data types, string concatenation, and function output. Sharpen your skills and improve your understanding of this popular programming language.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free