Home > Web Front-end > JS Tutorial > body text

jsBasics_Practice

Linda Hamilton
Release: 2024-11-23 06:47:15
Original
150 people have browsed it

jsBasics_Practice

Basics

What are the types of these variables listed below ? Verify this with typeof and output the result to the console:

let str1 = 'Laurence';
console.log(typeof (str1));   //string
let str2 = "Svekis";
console.log(typeof (str2));  //string
let val1 = undefined;
console.log(typeof (val1));  //undefined
let val2 = null;
console.log(typeof (val2));  //object
let myNum = 1000;
console.log(typeof (myNum)); //number
Copy after login

What data type is the following variable?

const c = "5"; //string
const d = 91;  // number
Copy after login

Which one is generally better, line 1 or line 2?

let empty1 = undefined; //line 1
let empty2 = null; //line 2
Copy after login

What is the console output for the following?

let a1 = "Hello";
a1 = "world";
console.log(a1);  //world
Copy after login
let a2 = "world";
let b2 = Hello ${a2}!;
console.log(b2);  // Helloworld
Copy after login

What is the value..?

let a4 = 5;
let b4 = 70;
let c4 = "5";
b4++;
console.log(b4);  //71
Copy after login

let result = 3 4 * 2 / 8; // 4, doesn't print anything as we didn't log the result.

let firstNum = 5;
let secondNum = 10;
firstNum++;
secondNum--;
let total = ++firstNum + secondNum;
console.log(total);  //16
let total2 = 500 + 100 / 5 + total--;
console.log(total2);  // 536
Copy after login
const a = 5;
const b = 10;
console.log(a > 0 && b > 0);  // true
console.log(a == 5 && b == 4);  // false
console.log(true || false);  // true
console.log(a == 3 || b == 10);  // true
console.log(a == 3 || b == 7);  // false
Copy after login

Create an array to use as your shopping list with 3 items: "Milk," "Bread," and

"Apples". Check your list length in the console. Update "Bread" to "Bananas". Output your entire list to the console.

The above is the detailed content of jsBasics_Practice. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template