0% found this document useful (0 votes)
4 views1 page

JavaScript Variables DataTypes Practice

The document explains variable declarations in JavaScript using `var`, `let`, and `const`, highlighting their scopes and reassignment capabilities. It outlines the dynamic typing of JavaScript, detailing primitive and non-primitive data types, and introduces the `typeof` operator for determining variable types. Additionally, it includes practice questions to reinforce understanding of variable declaration, data types, and the `typeof` operator.

Uploaded by

k4450992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

JavaScript Variables DataTypes Practice

The document explains variable declarations in JavaScript using `var`, `let`, and `const`, highlighting their scopes and reassignment capabilities. It outlines the dynamic typing of JavaScript, detailing primitive and non-primitive data types, and introduces the `typeof` operator for determining variable types. Additionally, it includes practice questions to reinforce understanding of variable declaration, data types, and the `typeof` operator.

Uploaded by

k4450992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JavaScript: Variables and Data Types

1. Variable Declarations

JavaScript uses `var`, `let`, and `const` to declare variables:

- `let` is block scoped and allows reassignment.

- `const` is block scoped and cannot be reassigned.

- `var` is function scoped (older; not recommended).

2. Data Types

JavaScript is dynamically typed. Common data types include:

- Primitive: String, Number, Boolean, Null, Undefined, BigInt, Symbol

- Non-Primitive: Object, Array, Function

3. typeof Operator

The `typeof` operator returns the type of a variable.

Example: `typeof "hello"` returns "string".

Practice Questions

Q1: Declare a variable using `let` to store your favorite programming language.

Q2: Declare a constant using `const` to store the name of your country.

Q3: Create an object `book` with keys: `title`, `author`, and `pages`.

Q4: Create an array `colors` with at least 3 color names.

Q5: Use `typeof` to print the data types of your variables from Q1, Q2, Q3, and Q4.

Q6: What will be the output of `typeof null` and why is it considered a bug in JavaScript?

You might also like